《c程序设计语言》-3.2 字符串转换
#include <stdio.h> #define Num 1000 int main() { int i = 0,j,k,count2 = 0; char s[Num] = {'\0'},t[Num]; int c; while((c = getchar()) != EOF ) { t[count2] = c; count2++; } while( t[i] != EOF && t[i] != '\0' ) { switch(t[i]) { case '\n': { s[j++] = '\\'; s[j++] = 'n'; i++; break; } case '\t': { s[j++] = '\\'; s[j++] = 't'; i++; break; } default: { s[j++] = t[i]; i++; break; } } } printf("\n"); for(k = 0;k < j;k++) printf("%c",s[k]); return 0; }