问题:
如何将Source数组转换为Destination格式的数组?
Source:
127 150 141 164 040 144 157 040 171 157 165 040 143 141 154 154 040 141 040 163 165 142 163 164 141 156 143 145 040 143 157 156 164 141 151 156 151 156 147 040 157 156 154 171 040 157 156 145 040 153 151 156 144 040 157 146 040 141 164 157 155 077
Destination:
'\127','\150','\141','\164','\040','\144','\157','\040','\171','\157','\165','\040','\143','\141','\154','\154','\040','\141','\040','\163','\165','\142','\163','\164','\141','\156','\143','\145','\040','\143','\157','\156','\164','\141','\151','\156','\151','\156','\147','\040','\157','\156','\154','\171','\040','\157','\156','\145','\040','\153','\151','\156','\144','\040','\157','\146','\040','\141','\164','\157','\155','\077'
------解决思路----------------------
将空格替换为','\
参考下面:
#include <stdio.h>
#include <string.h>
char s[256];
char *p;
int r,n,i;
int main() {
while (1) {
printf("请输入一行文字(空行结束),\"%%20\"将替换为\" \",\"你懂得\"将替换为\"XXXXXX\":\n");
fgets(s,256,stdin);
if ('\n'==s[0]) break;
p=s;
while (1) {
p=strstr(p,"%20");
if (p) {
memmove(p+1,p+3,strlen(p)-3+1);
p[0]=' ';
} else break;
}
p=s;
while (1) {
p=strstr(p,"你懂得");
if (p) {
memmove(p+6,p+6,strlen(p)-6+1);
for (i=0;i<6;i++) p[i]='X';
} else break;
}
printf("%s",s);
}
return 0;
}
//请输入一行文字(空行结束),"%20"将替换为" ","你懂得"将替换为"XXXXXX":
//abcdefg%20helloworld%20something.pdf
//abcdefg helloworld something.pdf
//请输入一行文字(空行结束),"%20"将替换为" ","你懂得"将替换为"XXXXXX":
//这是测试文字你懂得,在这个你懂的地方,就得做你懂得的事
//这是测试文字XXXXX,在这个你懂的地方,就得做XXXXX的事
//请输入一行文字(空行结束),"%20"将替换为" ","你懂得"将替换为"XXXXXX":
//
------解决思路----------------------
将空格替换一下即可。