Consider this block of C++ code.
if(_kbhit()){
//printf("Enter\n");
c = getchar();
int d = c;
printf("%d", d);
//printf("Exit \n");
}
The output I get is
sd115d100s100
If I press s, d and then d, s. Weird thing is that when I pressed some character, the ascii of previously pressed character was displayed.
Now consider,
if(_kbhit()){
printf("Enter\n");
c = getchar();
int d = c;
printf("%d", d);
printf("Exit \n");
}
The output I got this time is
aEnter
97
Exit
dEnter
100
Exit
dEnter
100
Exit
aEnter
97
Exit
Now everything is correct the ascii code of correct character is being displayed after I pressed a character.
Why this anomaly ? How can I correct this anomaly ?