I am trying to print escape sequences in this program:
/*print escape sequences*/
#include <stdio.h>
int main()
{
int esc;
printf("Hit any escape sequence:");
esc=getchar();
//scanf("%d",&esc);
switch(esc){
case '\t':
printf("tab");
break;
case '\n':
printf("newline");
break;
case '\b':
printf("backspace");
break;
}
printf("\n");
return 0;
}
The thing is I tried doing this with scanf
and it never printed anything.
Then I tried with getchar
and it prints tab and newline. But backspace I couldn't get it to print backspaces.
How to print backspace?