I have a dynamically allocate 2d array pointing to a structure. I'm trying to fill the NULL values of the array with the number 0. There are no errors or warnings it's just printing some random values.
This is a simplified version of the code:
#include <stdio.h>
#include <stdlib.h>
int rows = 2, cols=3 ;
struct Data
{
    int trail;
};
struct Data** WritingData()
{
    //initializing 2d array
    struct Data **arr = (struct Data**)malloc(rows * sizeof(struct Data*));
    for (int i=0; i<cols; i++)
         arr[i] = (struct Data*)malloc(cols * sizeof(struct Data));
    //giving some values as an example
    (*(arr+0)+0)->trail = 1;
    (*(arr+1)+0)->trail = 1;
    (*(arr+0)+1)->trail = 1;
    //checking if value is NULL to replace with 0
    for (int i = 0; i < rows ; i++) {
        for (int j = 0; j < cols; j++){
              if (!((*(arr+i)+j)->trail))
             (*(arr+i)+j)->trail = 0;
              else continue;
            }
        }
    return(arr);
}
int main()
{
    struct Data **arr = WritingData();
    //printing result
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++)
        {
        printf(" %d ", (*(arr+i)+j)->trail);
        }
    printf("\n");
    }
    free(arr);
}
 
    