0

I'm in need to get the size of a dynamically allocated 2-Dimensional array, however the array is full of 0's (on a specific row), iterating through the rows results in the entire loop breaking due to the NULL pointer being '0'.

Assigning a different terminating character to a "row" doesn't seem to be able to work and causes a segfault.

Every column in the row:

0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0  0

The code for getting the size ( side note: I'm unable to make use of standard libraries nor mind my syntax, it's due to my studies norm.):

int     ft_2d_len(char **arr)
{
    int index;

    index = 0;
    while (arr[index] != NULL)
        index++;
    return (index);
}
VADE
  • 5
  • 3

1 Answers1

0

What you are trying to achieve is not possible. The input pointer points to some address in memory, there is no "marker" that signals the end of some block of higher level data. The only way to do this, would be some kind of 'end of array' string that can only be used to indicate that the last string read was the last string in the array. If you want to know how many entries there are you should store the length in a variable when you allocate the array.

SilverTear
  • 695
  • 7
  • 18