Consider this:
Is there another way to access the word "world"?Code:#include <stdio.h> int main(void) { int c; char *argv[] = {"hello", "world"}; printf("%s\n", argv[1]); while (c = *(argv[1])++) putchar(c); return 0; }
Consider this:
Is there another way to access the word "world"?Code:#include <stdio.h> int main(void) { int c; char *argv[] = {"hello", "world"}; printf("%s\n", argv[1]); while (c = *(argv[1])++) putchar(c); return 0; }
argv[1] is equivalent to *(argv + 1), but since they're the same thing just expressed differently, I don't know that I'd call that another way.
You could declare a pointer to argv and access it that way.
Is this allowed?
I'm pretty sure it's C99, but what about C89? I thought you had to goCode:while (c = *(argv[1])++)
in C89.Code:while ((c = *(argv[1])++))
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
dwks, why do you think C89 requires a redundant pair of parentheses there?
gcc with -Wall (and probably other compilers) will suggest an extra pair because it thinks you might have made a mistake, and meant ==. It can't tell that you know what you're doing and really want to assign a value to c and test the result instead of wanting to compare.