练习3-2

来源:互联网 发布:网络剧余罪第一季 编辑:程序博客网 时间:2024/06/06 04:16
#include <stdio.h>/*3-2 输出转义字符序列 与反义输出*/void escape(char* s, char* t);void unescape(char* s, char* t);int main(){char s[20] = {0};char t[20] = "Hello\tworld\n";escape(s, t);printf("%s\n", s);unescape(s, t);printf("%s\n", t);return 0;}void escape(char* s, char* t){while(*t != '\0'){switch(*t){case '\t':*s++ = '\\';*s++ = 't';t++;break;case '\n':*s++ = '\\';*s++ = 'n';t++;break;default:*s++ = *t++;break;}}*s = '\0';}void unescape(char* s, char* t){while(*s != '\0'){switch(*s){case '\\':if(*(s+1) == 't'){*t++ = '\t';s+=2;break;}else if(*(s+1) == 'n'){*t++ = '\n';s+=2;break;}default:*t++ = *s++;break;}}*t = '\0';}


0 0
原创粉丝点击