Well, this code below usually works.
Code:
#include <stdio.h>
do
{
fflush(stdin);
command = getch();
}while(tolower(command) != 'p' && tolower(command) != 's');
switch(tolower(command))
{
case 'p':
{
printf("p");
break;
}
case 's':
{
printf("s");
break;
}
default:
{
printf("WTF did you do to make it go to default when it just came out of a loop that it requires it to be one or the other?");
break;
}
}
However, when I add some int values to it so that it can't be certain keys, which it was doing IE: ? == F5 and PgDwn == S and Right Arrow == M I don't know why it started to do this. The only thing we could figure out to fix it is:
Code:
do
{
fflush(stdin);
command = getch();
}while(command != 'p' && command != 's' && command != 241 && command != 0);//I think this is the arrow
//keys primary ascii value
tolower(command);//note this work...i dont know why
//tolower shouldnt change the actual value in the variable
switch(tolower(command))
{
case 'p':
{
printf("p");
break;
}
case 's':
{
printf("s");
break;
}
default:
{
printf("WTF did you do to make it go to default when it just came out of a loop that it requires it to be one or the other?");
break;
}
}
I have no idea why tolower(command); does ANYTHING...