c语言编写程序编写函数escapest将字符串t拷贝到字符串s中并在拷贝过程中将诸如换行符与制表符转换成诸如nt等换码序列编写一个程序将输入的字符串含有换行符制表符进行转换并输出控制台输入字符串t t中可能含有换行符和制表符。t的长度不超过50个字符。控制台输出对t进行换码序列转换后的字符串s
#include <stdio.h>
void escape(char s[], char t[]) { int i, j; for (i = 0, j = 0; t[i] != '\0'; 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++; } s[j] = '\0'; }
int main() { char t[51], s[101]; printf("请输入字符串t:"); fgets(t, 51, stdin); escape(s, t); printf("转换后的字符串s为:%s", s); return 0;
原文地址: https://www.cveoy.top/t/topic/f8H6 著作权归作者所有。请勿转载和采集!