-
while loop char input
Hey guys is there anything wrong with how im getting the input for a single character because for some reason the if statement is not working properly.
Even if i do enter the correct input it still prints as invalid?
Code:
char guessType()
{
char type;
int valid;
printf("Enter guess type((f)lag, (u)ncover or(s)weep:\n");
valid = 0;
while((type = fgetc(stdin) != '\n' && type != EOF))
{
if(type != 's' || type !='u' || type != 'f')
{
printf("invalid");
}
break;
}
-
Your if() statement should test as follows:
Code:
if(type != 's' && type !='u' && type != 'f')
-
>char type;
>type = fgetc(stdin)
fgetc() doesn't return a char, it returns an int.
http://faq.cprogramming.com/cgi-bin/...&id=1043284351