samir82show

c_ch01_ex10.c

Sep 22nd, 2014
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. /*Exercise 1-10. 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
  2. visible in an unambiguous way */
  3.  
  4. #include <stdio.h>
  5. int main()
  6. {
  7. int flag = 0, c;
  8. while ((c = getchar()) != EOF) {
  9. switch (c) {
  10. case '\t': printf("\\t");
  11. break;
  12. case '\b': printf("\\b");
  13. break;
  14. case '\\': printf("\\\\");
  15. break;
  16. default : putchar(c);
  17. }
  18. }
  19. return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment