So are you actually initializing the items you allocate to have NULL pointers, or are you just praying they randomly have that value?
Quzah.
So are you actually initializing the items you allocate to have NULL pointers, or are you just praying they randomly have that value?
Quzah.
Hope is the first step on the road to disappointment.
Well, that's where I'm stuck. I dynamically allocate (with calloc) the space needed for my array of country structures:After that, I don't really know how to work with that array anymore. I've never read or used anything that does this. SorryCode:db->list = (struct Country *)calloc( countries, sizeof( struct Country ) );
Some of the code provided by my teacher makes me doubt what I'm doing (not that I was ever sure):I should be able to use that same "db->list+i" part to check the array, right? I'm just trying to find the first free element to insert my country into...Code:for( i = 0; i < db->ncountries; i++ ) { delete_country( db->list+i ); // free mem alloc to a country }
Data structures are so much easier, but I'm stuck with these parameters!
But anyway , using calloc , the space is initializied to zero.After that, I don't really know how to work with that array anymore. I've never read or used anything that does this
to loop the array :
Code:int i; for( i = 0; i < db->ncountries; i++ ) db->list[i] = NULL; /* or *(db->list+i) = NULL; */
Why don't u post the all code ?