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;
}
Printable View
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])++))
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.