using NULL sentinel instead of num_states

This commit is contained in:
Dan Buch 2011-09-09 14:34:26 -04:00
parent 16785fe9f2
commit 5b7748c99a

9
ex10.c
View File

@ -10,12 +10,13 @@ int main(int argc, char *argv[])
char *states[] = {
"California", "Oregon",
"Washington", "Texas"
"Washington", "Texas",
NULL
};
int num_states = 4;
char *state = "";
for(i = 0; i < num_states; i++) {
printf("state %d: %s\n", i, states[i]);
for(i = 0; NULL != (state = states[i]); i++) {
printf("state %d: %s\n", i, state);
}
return 0;