C program to replace tab by \t, backspace by \b and \ by \\

#include<stdio.h>
#include<conio.h>
main()
{     int i,n;
char a[100];
printf(“\nEnter string\n” );

for(i=0;( ( n=(int)getche() )!=13);i++)
{
if(n==8){  a[i]=’\\’,a[++i]=’b’;}
else if(n==9){ a[i]=’\\’,a[++i]=’t’;}
else if(n==92) {a[i]=’\\’,a[++i]=’\\’;}
else { a[i]=char(n);}
}
a[i]=”;
printf(“\n\n”);
printf(“%s”,a);
getch();

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: