7-6 exercise 1-10 (20分)
Write a program to copy its input to its output.The character received from input can be a tab, a backspace, a backslash, or anything else. If it is a tab, we replace it with \t, a backspace with \b, and a backslash with \. Anything else is printed as is. This makes tabs and backspaces visible in an unambiguous way.
Input Format:
text
Output Format:
modified text
Sample Input:
a s
Notes: There is a tab character between character a and b.
Sample Output:
a\ts
#include<stdio.h>
int main()
{
char c;
while ((c = getchar()) != EOF)
{
if (c == '\b')//\b代表是Backspace,即回退一格
printf("\\b");
else if (c == '\t')//\t 代表的意思是水平制表符,相当于按了键盘上的TAB按键
printf("\\t");
else if (c == '\\')//'\\'代表的是'\'
printf("\\\\");
else
putchar(c);
}
return 0;
}