Switch to NULL-terminated 2D array

This commit is contained in:
Dan Buch 2024-04-19 20:44:43 -04:00
parent 5381d5f0ce
commit d4b5c737e5
Signed by: meatballhat
GPG Key ID: A12F782281063434

View File

@ -11,13 +11,14 @@ int main(int argc, char *argv[])
// let's make our own array of strings // let's make our own array of strings
char *states[] = { char *states[] = {
"California", "Oregon", "California",
"Washington", "Texas", "Oregon",
"Washington",
"Texas",
NULL,
}; };
int num_states = 4; for (i = 0; states[i] != NULL; i++) {
for (i = 0; i < num_states; i++) {
printf("state %d: %s\n", i, states[i]); printf("state %d: %s\n", i, states[i]);
} }