Hi!
EDIT: this was an irrelevant post - the array size is specified in the program I am referring to, so no magic. I can't delete the post, so I am sorry if you have lost your time reading it.
Please, help me to understand how the size of the array is used in the following part of the program, which I have found on this forum.
We define the size of the array as
Code:
#define ARRAYLENGTH(x) (sizeof(x)/sizeof(*(x)))
Then in the program we get information from the file and put that into the array using the for loop. My question about the condition of the loop
Code:
j < ARRAYSIZE(*array)
: when the loop starts, the array is not yet populated, so the size is equal to sizeof(the whole array which is null at the first iteration of the loop)/sizeof(first member of the array)). Please, help me to understand how this condition works, and how to interpret it.
Code:
for ( i = 0; fgets(buffer, sizeof buffer, file); ++i )
{
for ( j = 0, ptr = buffer; j < ARRAYLENGTH(*array); ++j, ++ptr )
{
array[i][j] = (int)strtol(ptr, &ptr, 10);
}
}
Thanks a lot!