khalfella

c_ch01_ex10.c

Sep 20th, 2014
306
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. /*
  2. * Exercise 1-10.
  3. * Write a program to copy its input to its output, replacing each
  4. * tab by \t, each backspace by \b, and each backslash by \\. This
  5. * makes tabs and backspaces visible in an unambiguous way.
  6. */
  7.  
  8. #include <stdio.h>
  9.  
  10. main() {
  11. int c;
  12.  
  13. while ((c = getchar()) != EOF) {
  14. if (c == '\t') {
  15. putchar('\\');
  16. putchar('t');
  17. } else if (c == '\b') {
  18. putchar('\\');
  19. putchar('b');
  20. } else if (c == '\\') {
  21. putchar('\\');
  22. putchar('\\');
  23. } else
  24. putchar(c);
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment