Ques) Write a program to copy its input to its output, replacing each tab by \t
, each backspace by \b
, and each backslash by \\
. This makes tabs and backspaces visible in an unambiguous way.
Ans.)
while ((c = getchar()) != EOF) {
// Detect/translate special characters.
if (c == '\t') {
putchar ('\\');
putchar ('t');
continue; // Go get next character.
}
if (c == '\b') {
putchar ('\\');
putchar ('b');
continue; // Go get next character.
}
if (c == '\\') {
putchar ('\\');
putchar ('\\');
continue; // Go get next character.
}
// Non-special, just echo it.
putchar (c);
}
i didnt get this code, someone pls explain it .. why are we outputting "\\" and then "t" or "b" separately?
is it because , suppose we have a blank now we have to replace it with '\b' and now each '\' is to be replaced with '\\' . am i geting it right or wrong?
and also i didnt get the third case when c='\\' .