say I have declare a struct
struct mystruct {
char a[10];
double b;
}
struct mystruct array[20] = {
{'test1',1.0},
{'test2',2.0} <---- I just want to declare 2 items first because I am going to add new ones later.
};
int i;
for( i=0; array[i].a != NULL ;i++){
.... <--- so here I just want to display what is initialized first
}
However, the for loop display past the 2 items ( ie to 20 items but all the rest are garbage ). I just want to display currently only what is initialized, even though i declared to store 20 of them. How to do it? thanks.
I am using C90 standard. Also, let's say I added more items in future , but still lesser than 20 items, i would just want to display until the "last item that is valid" .
array[i].aagainst NULL worries me significantly as to the code your not showing us in: "...initialize ok here with just 3 items".{ "test1", 1.0 },etc in the initializers; you're using a multi-character character literal, which is non-portable.array[i].awill never be null. You want to checkarray[i].a[0] != 0, if I understand your intent. Oh, and try "test1" etc. I've a feeling you'll be more pleased with that."test1"instead of'test1'.