I have an array of structs which I will be going through one-by-one to search for a matching value. This array might have elements added and removed later, so I don't want to have to update a defined size for the array. What I'd like to do is put a NULL struct at the end so that the end can be detected.
Here's some code:
Then later I want to be able to do something like
Basically I need to be able to know when to quit searching through the array. When I try putting a NULL at the end of the array:
I get "warning: initialization makes integer from pointer without a cast" (for the initialization of the array) and "error: invalid operands to binary !=" (for the while loop).
Suggestions?
Here's some code:
Code:
typedef struct smfMolTrans {
char molecule[SZFITSCARD]; /* molecule species */
char transiti[SZFITSCARD]; /* transition */
double freq; /* frequency of transition */
} molTrans;
static molTrans *transitions[] = {
{"SO", "4 5 - 3 4", 178605.403000},
{"CH", "2 -1 3 3 - 2 1 2 2", 178875.247400},
{"SiCC", "8 0 8 - 7 0 7", 179446.496000},
/*.... a bunch more....*/
};
Code:
while ( transitions[i] != NULL ) {
/* check to see if the frequency matches, do some stuff... */
}
Code:
static molTrans transitions[] = {
{"SO", "4 5 - 3 4", 178605.403000},
{"CH", "2 -1 3 3 - 2 1 2 2", 178875.247400},
{"SiCC", "8 0 8 - 7 0 7", 179446.496000},
/*.... a bunch more....*/
NULL
};
Suggestions?
Comment