C
Chad
The program:
#include <stdio.h>
void hello(void) {
printf("hello \n");
}
void hi(void) {
printf("hi \n");
}
void no(void) {
printf("no\n");
}
int main(int argc, char *argv[]) {
int c;
while(--argc > 0)
while(c = *++argv[0])
switch(c) {
case 'a':
hello();
break;
case 'b':
hi();
break;
default:
no();
break;
}
return 0;
}
And here is what I get.
chad@linux:~/flood> gcc -g -Wall switch.c -o switch
switch.c: In function `main':
switch.c:19: warning: suggest parentheses around assignment used as
truth value
chad@linux:~/flood> ./switch
chad@linux:~/flood> ./switch a
no
no
no
no
no
no
no
chad@linux:~/flood> ./switch b
no
no
no
no
no
no
no
chad@linux:~/flood>
What is my error in logic here?
Chad
#include <stdio.h>
void hello(void) {
printf("hello \n");
}
void hi(void) {
printf("hi \n");
}
void no(void) {
printf("no\n");
}
int main(int argc, char *argv[]) {
int c;
while(--argc > 0)
while(c = *++argv[0])
switch(c) {
case 'a':
hello();
break;
case 'b':
hi();
break;
default:
no();
break;
}
return 0;
}
And here is what I get.
chad@linux:~/flood> gcc -g -Wall switch.c -o switch
switch.c: In function `main':
switch.c:19: warning: suggest parentheses around assignment used as
truth value
chad@linux:~/flood> ./switch
chad@linux:~/flood> ./switch a
no
no
no
no
no
no
no
chad@linux:~/flood> ./switch b
no
no
no
no
no
no
no
chad@linux:~/flood>
What is my error in logic here?
Chad