khalfella

ansi_c_pg056_ch03_ex02.c

Dec 27th, 2014
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. void escape(const char* s, char* t) {
  4. int i,j;
  5. i = -1;
  6. j = 0;
  7. while(s[++i]) {
  8. switch(s[i]) {
  9. case '\n':
  10. t[j++] = '\\'; t[j++] = 'n';
  11. break;
  12. case '\t':
  13. t[j++] = '\\'; t[j++] = 't';
  14. break;
  15. default:
  16. t[j++] = s[i];
  17. }
  18. }
  19.  
  20. t[j] = '\0';
  21. }
  22.  
  23.  
  24. int
  25. main() {
  26. char t[100] = {0};
  27. escape("mohamed\t\n",t);
  28. printf ("t = %s\n", t);
  29. }
Advertisement
Add Comment
Please, Sign In to add comment