Hi,
I'm coding in Linux, and I found problems getting input. I can't make fflush() work, so often my scanf, getchar, getc... get a char from previous input.
so something like this
/*.... */
fflush(stdin)
scanf("%c", &c);
switch(c)
{
/*.... */
often runs without leting you write your char.
any idea?
For instance, this program doesn't work properly
#include <stdio.h>
int main(int argc, char **argv)
{
char c;
while(1)
{
printf("Press a key... \n");
fflush(stdin);
scanf("%c", &c);
switch(c)
{
case 'a':
printf("pressed %c\n\n", c);
break;
case 'b':
printf("pressed %c\n\n", c);
break;
case 'c':
printf("pressed %c\n\n", c);
break;
case 'd':
printf("pressed %c\n\n", c);
break;
default:
printf("No key from a to d pressed n\n");
break;
}
}
}
Thanx in advance.