Hello...
I'm learning C with "The C Programming Language" book, and I'm stuck at
exercise 1-10 which asks to:
"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."
Here is my code:
#include <stdio.h>
/* copy input to output, replacing each tab by \t,
each backspace by \b, and each backslash by \\ */
main()
{
int c;
int back;
while ((c = getchar()) != EOF) {
if (c == '\t') {
putchar('\\');
putchar('t');
}
if (c == '\b') {
putchar('\\');
putchar('b');
}
if (c == '\\') {
putchar('\\');
putchar('\\');
}
if (c != '\t')
if (c != '\b')
if (c != '\\')
putchar(c);
}
}
Everything is working fine, except that it won't print "\b" when the user presses
the backspace key. Could anyone give me a hint on how to solve this?