How do I count the posts in an array?
How do I count the posts in an array?
What on earth do you mean??? You'll have to elaborate a bit, my mind-reading skills ain't what they used to be
How do i know how many variables there are in an array?
Like
int hello[x];
How do i know how many "there are" in that array without "touching" variable x.
I suppose you remember that hello[x] is not valid if x is not a constant? (Though this is e.g. a GNU extension in gcc compiler)
int hello[x];
sizeof(hello)/sizeof(int) is maybe what you want?
You cannot use sizeof on an array directly.
Using sizeof(hello); would return 4, whatever size the array have, since hello is a pointer (sort of) and not the whole array.
To get the length, you need to store its size when you create it. I know of no other way...
That is not the case. When a pointer is passed as a parameter to sizeof it returns the size of the pointed structure in bytes. Therefore this statement (sizeof(hello)/sizeof(int)) returns the number of elements in the array of type int*.
But this won't work for dynamically allocated arrays which was not the case.
Last edited by raimo; 06-29-2002 at 11:29 AM.