The K&r exercise 3-2,escape (s,t) converts \n,\t into a visible escape sequence, and the Rescape function instead.
Wrote it myself:
#include <stdio.h> #define MaxLen 1024void Escape (char s[], char t[]) {int i=0; int j=0; while (t[i]!= ' ") {switch (T[i]) {case ' \ n ': s[j++]= ' \ \ '; s[j]= ' n '; Break Case ' \ t ': s[j++]= ' \ \ '; s[j]= ' t '; Break Default:s[j]=t[i]; Break } ++j; ++i; } s[j]= ' + ';} void Rescape (char s[], char t[]) {int i=0; int j=0; while (t[i]!= ') {if (t[i]== ' \ \ ') {++i; Switch (T[i]) {case ' t ': s[j]= ' \ t '; Break Case ' n ': s[j]= ' \ n '; Break Case ' \ \ ': s[j]= ' \ \ '; Break Default:s[j]=t[i]; Break }}else{S[j]=t[i]; } ++i; ++j; } s[j]= ' + ';} int main () {int i=0; Char A[maxlen]; Char b[]= "Hesdf ksdf\n,jj\t\tllw"; Escape (A, b); while (a[i]!= ') Putchar (a[i++]); Putchar (' \ n '); Rescape (A, b); while (a[i]!= ') ' Putchar (a[i++]; putchar (' \ n '); return 0;}
Compared to the simplicity of the answer.
C language Escape,rescape