I'm guessing it's something about buffering , but I'm not sure.It isn't. Note that you're doing chomp($ans=<STDIN>); in your perl code, while you're not doing anything like that in the C code.
Gives:#include <stdio.h> int main() { char answer=' '; printf("(F)irst,(S)econd,(T)hird\n"); scanf("%c",&answer); while(answer !='F' && answer !='S' && answer !='T') { printf("answer was: '%c', which is not what I want\n",answer); printf("(F)irst,(S)econd,(T)hird\n"); scanf("%c",&answer); } return 0; }
$ ./a.out (F)irst,(S)econd,(T)hird a answer was: 'a', which is not what I want (F)irst,(S)econd,(T)hird answer was: ' ', which is not what I want (F)irst,(S)econd,(T)hird
In reply to Re: Why does perl get this right and C doesn't ?
by Joost
in thread Why does perl get this right and C doesn't ?
by Alien
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |