// lib -------------------------------------------------------------------------------------------------------
# include <stdio.h>
// defines --------------------------------------------------------------------------------------------------------
# define X_Ascii (88)
# define H_Ascii (72)
# define ENTER_Ascii (13)
// func --------------------------------------------------------------------------------------------------------
int print_help()
{
printf("welcome to one of the shitest programs ever written""\n\n");
printf("the controls for this program are as follows:""\n");
printf(" X = close""\n");
printf(" H = help(this message)""\n\n");
printf("enjoy your aids!""\n");
return 0;
}
// main --------------------------------------------------------------------------------------------------------
int main( )
{
print_help();
char key;
do
{
key = getchar();
switch(key)
{
case H_Ascii:
print_help();
break;
case ENTER_Ascii:
break;
default:
printf("error: command not recognised\n");
printf("press 'H' for help\n");
break;
}
}while (key != X_Ascii);
return 0;
}
so the problem is this gentlemen, when the user presses the key for his desired function then hits enter it performs said function, but also gives the "default" message aswell. i believed first that i might have an issue with it processing the enter key as well so i added the enter case to try and prevent that but nothing. what the hell is causing it to behave like this?
edit: weird looked better in the vs2010 ide, guess this uses spaces for tabs
Why don't you print out the character getchar() is returning? That will help you track down the problem. I strongly recommend printing it out either in decimal or hexadecimal.