I have an array of pointers to structs.
struct key {
int *data;
};
struct key *entry = NULL;
entry = malloc(sizeof(entry));
Reallocated a bit of times:
node = realloc(node, (length+1)*sizeof(node[0]));
node[length].data = some_int;
In another part of my program, I want to iterate through it. I don't know how much elements it is containing at the moment.
for (i=0; &(node[i]) != NULL; i++)
length = i;
But I have infinity loop. Because:
(gdb) p node[i]
$1 = {data = 0x0}
It seems to like an uninitialized value, but it is not NULL pointer.
How to determine the end of an array?
Why it is not NULL pointer?
reallocdoes not initialise the new memory blocks which it has allocated to 0, if you want that thing you have to do it yourself. But I recommend you to store the "used" length somewhere, and only iterate through that length, since the "empty" blocks are don't matter. (of course store the allocated length somewhere else, to know, how much blocks you have left)nodeis of which type? And if is ofstruct key *why do you assign "some int" to a pointer toint, that is aint *?NULL-terminated array like proposed in your answer ... @MohitJain