I can't seem to wrap my head around the problem. What am I missing?
Consider the following
int main(int argc, char *argv[]) { while ( *argv ) { printf("argv[] is: %s\n", *argv); ++argv; } return 0; }
This prints out each argv value. Thus, on a command line such as ./example arg1 arg2 , the following is displayed:
`argv[] is: ./example` `argv[] is: arg1` `argv[] is: arg2`
Now consider the following (which I'm having problems with):
int main(void) { char *days[] = { "Sunday", "Monday", "Tuesday" }; while ( *days ) { printf("day is %s\n", *days); *days++; } return 0; }
If I try to compile, I get an error message cannot increment value of type 'char *[3]'
If I change *days++ to (*days)++ , it compiles. If I run it, it will work forever and eventually end with a bus error .
However, it does not iterate over each value of days[] . I even tried putting a Null pointer in the form of '\0' and "\0" in the days array with no effect.
What am I missing?
c arrays pointers
fizzy drink
source share