V
VivekR
Hi,
Consider the program snippet below
main
{
....
printf("Enter Choice: ");
int choice = getche();
switch(choice)
{
case '1':
printf("Enter Num:");
int num;
scanf("%d", &num);
.....
break;
// some other cases like '2', '3' etc
case '5':
int x = getche();
...
}
}
My problem is when i type 1 or 2 for the "int choice = getche", I land
on the right case but the scanf reads and displays the previuously
entered character. But that does not happen for case '5'. I tried using
fflush(stdin) still it does not work.
Let me know what is wrong with my usage.
Thanks
Vivek Ragunathan
Consider the program snippet below
main
{
....
printf("Enter Choice: ");
int choice = getche();
switch(choice)
{
case '1':
printf("Enter Num:");
int num;
scanf("%d", &num);
.....
break;
// some other cases like '2', '3' etc
case '5':
int x = getche();
...
}
}
My problem is when i type 1 or 2 for the "int choice = getche", I land
on the right case but the scanf reads and displays the previuously
entered character. But that does not happen for case '5'. I tried using
fflush(stdin) still it does not work.
Let me know what is wrong with my usage.
Thanks
Vivek Ragunathan