diff options
Diffstat (limited to 'ch01/ex10-replace.c')
| -rw-r--r-- | ch01/ex10-replace.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/ch01/ex10-replace.c b/ch01/ex10-replace.c new file mode 100644 index 0000000..b7ec4a5 --- /dev/null +++ b/ch01/ex10-replace.c @@ -0,0 +1,26 @@ +#include <stdio.h> + +/* replace each tab by \t, each backspace by \b, and each backslash by \\ */ +int main() +{ + int c; + + 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); + } +} |
