-
Keyboard Input
i'm reading in characters from the keyboard and i'm wanting to check if the character entered is a backspace and if it is i want to output the ASCII value 08.
i have this snippet of my code:
c = fgetc(stdin);
if (c== '\127')
fputc('\08',stdout);
I'm not sure if this is right as it doesn't seem to be working
-
Unfortunately, with buffered input you can't read a backspace keypress with fgetc. You'll need to use a raw input function such as getch:
Code:
#include <stdio.h>
#include <conio.h>
int main ( void )
{
int c;
c = getch();
if ( c == '\b' )
printf ( "Backspace pressed\n" );
return 0;
}
-Prelude