cleaning up for-loops again

This commit is contained in:
Dan Buch 2011-09-09 14:32:33 -04:00
parent 7fbe80ce25
commit 16785fe9f2

9
ex10.c
View File

@ -3,10 +3,9 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int i = 0; int i = 0;
char *arg = "";
for(i = 0, arg = ""; i < argc && (arg = argv[i++]);) { for(i = 0; i < argc; i++) {
printf("arg %d: %s\n", i, arg); printf("arg %d: %s\n", i, argv[i]);
} }
char *states[] = { char *states[] = {
@ -15,8 +14,8 @@ int main(int argc, char *argv[])
}; };
int num_states = 4; int num_states = 4;
for(i = 0, arg = ""; i < num_states && (arg = states[i++]);) { for(i = 0; i < num_states; i++) {
printf("state %d: %s\n", i, arg); printf("state %d: %s\n", i, states[i]);
} }
return 0; return 0;