Understand backspace (\b) behaviour in C -


this program copy input output, replacing tab(\t) \t backspace(\b) \b. here in code unable read input character when enter backspace not replacing tab works .

compiling gcc in linux:

#include<stdio.h> int main(void) {     int c=0;     while((c=getchar())!=eof){      if(c=='\t'){       printf("\\t");      if(c=='\b')       printf("\\b");     }     else      putchar(c);  } return 0; } 

suppose if type vinay (tab) hunachyal

output:vinay\thunachyal  

if type vinay(and 1 backspace)

output:vina 

so query why vina\b not printing in case?
possible detect \b , print \b? if not whats reason

note: need @ run time input backspace not providing separate file having \b

the backspace consumed shell interpreter, program never see it, code (slightly) broken, due misplaced braces, not helped poor indentation.

here corrected version:

#include<stdio.h> int main(void) {     int c=0;     while((c=getchar())!=eof){         if(c=='\t')             printf("\\t");         else if(c=='\b')             printf("\\b");         else             putchar(c);     }     putchar('\n');     return 0; } 

which works expected:

$ echo 'vinay\thunachyal\b' | ./escape vinay\thunachyal\b 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -