编写函数escape(s,t),将字符串t复制到字符串s中,
将换行符、制表符这两种不可见字符分别转换为\n、\t这两个可见的转义字符序列
void escape(char s[], char t[]) { int i = 0, j = 0, time = 0; while(t[i]!='\0') { switch(t[i]) { case '\t': s[j++] = '\\'; s[j++] = 't'; i++; break; case '\n': s[j++] = '\\'; s[j++] = 'n'; i++; break; default: s[j++] = t[i++]; } } s[j]='\0'; }
编写函数unescape(s,t),将字符串t复制到字符串s中,
将\n、\t这两个可见的转义字符序列分别转换为对应的换行符、制表符这样的实际字符
void unescape(char s[], char t[]) { int i = 0, j = 0; while(t[i]!='\0') { switch(t[i]) { case '\\': if(t[i+2]=='\0') { s[j++] = '\0'; break; } else switch(t[++i]) { case 'n': s[j++] = '\n'; i++; break; case 't': s[j++] = '\t'; i++; break; }break; default: s[j++] = t[i++]; } } s[j] = '\0'; }