From 5b7748c99a81be851388f01f19a7c2110ccbebd1 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Fri, 9 Sep 2011 14:34:26 -0400 Subject: [PATCH] using NULL sentinel instead of num_states --- ex10.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ex10.c b/ex10.c index c06d77b..d0aed12 100644 --- a/ex10.c +++ b/ex10.c @@ -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;