c - program to copy its input to output by replacing each backspace by \b -


int main()     {    int c, d;    while ( ( c = getchar() ) !=  eof )    {       d = 0;       if (c == '\b')       {           putchar('\\');               putchar('b');           d = 1;       }       if (d == 0)           putchar(c);    }      return 0; } 

but when press backspace \b not being displayed in place of that

but when press backspace \b not being displayed in place of that

your code compiles fine, backspace won't printed console. unlike other format characters, backspace won't show up.

the reason is, mentioned above:

getchar() 

places input buffer, reads, outputs text once press enter. logically, backspace character won't printed result, unlike tabs or spaces.

getch() 

getch() output backspace; not read standard input, , instead returns input without waiting press enter. getch() part of 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 output value of backspace , print backspace screen when entered.

int d 

didn't need run program, use "else" instead of:

if(d == 0) 

i hope answer helps in way.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -