But when i press backspace \b is not being displayed in place of that
Your code compiles just fine, however backspace won't be printed to the console.
Unlike the other format characters, backspace won't show up.
The reason is, as mentioned above:
getchar()
Places your input into the buffer, reads, then outputs the text once you press enter. Logically, the backspace character won't be printed as a result, unlike tabs or spaces.
getch()
getch() will output backspace; it does not read from the standard input, and instead returns input without waiting for you to press enter. getch() is also a part of the conio.h header file.
#include <stdio.h>
#include <conio.h>
int main()
{
int c, d;
while ((c = _getch()) != EOF)
{
if (c == '\b')
{
printf("\\b");
printf("\nValue of backspace: %d \n", c);
}
else
putchar(c);
}
return 0;
}
Similar program that will output the value of backspace and will print backspace to the screen when entered.
int d
Didn't really need it to run the program, you could use "else" instead of:
if(d == 0)
I hope this answer helps you in some way.