如果我正确理解他/她,OP会做什么。 / *来自new.c的BEGIN输出* / helloworldbyebyeworld / *来自new.c的END输出* / / * BEGIN new.c * / #include< stdio.h> ; #include< string.h> int main(void) {char foo [128] =" hello,world,bye,bye ,world" ;; char *指针; for(pointer = foo; * pointer!=''\'''; ++指针){ if(*指针=='',''){ memmove(指针,指针+ 1,strlen(指针)); } } puts(" \ n / *来自new.c * / \ n")的BEGIN输出; puts(foo); puts(" \ n / * END输出来自new.c * /"); 返回0; } / * END new.c * / 我建议进行以下修改: #include< stdio.h> #include< string.h> #include< assert.h> #define MAXNUMENTRIES 5 int main(无效) { char foo [128] =" hello,world,bye,bye,world" ;; char *指针,* s [MAXNUMENTRIES + 1]; size_t i = 0; s [i ++] = foo; for(pointer = foo; * pointer!=''\'''; ++ pointer){ if(* pointer =='',''){ * pointer =''\\ \\ 0''; s [i ++] =指针+ 1; } 断言(i< = MAXNUMENTRIES); s [i] = NULL; / *表示有效条目的结尾* / puts(" \ n / * BEGIN输出来自new.c * / \ n"); for(i = 0; s [i]!= NULL; i ++) puts(s [i]); puts(" \ n / * END输出来自new.c * /"); 返回0; } Which is what the OP does, if I understood him/her correctly. /* BEGIN output from new.c */ helloworldbyebyeworld /* END output from new.c */ /* BEGIN new.c */ #include <stdio.h> #include <string.h> int main(void) { char foo[128] = "hello,world,bye,bye,world"; char *pointer; for (pointer = foo; *pointer != ''\0''; ++pointer) { if (*pointer == '','') { memmove(pointer, pointer + 1, strlen(pointer)); } } puts("\n/* BEGIN output from new.c */\n"); puts(foo); puts("\n/* END output from new.c */"); return 0; } /* END new.c */I would suggest the following modification: #include <stdio.h> #include <string.h>#include <assert.h> #define MAXNUMENTRIES 5 int main(void) { char foo[128] = "hello,world,bye,bye,world";char *pointer, *s[MAXNUMENTRIES+1];size_t i=0;s[i++] = foo; for (pointer = foo; *pointer != ''\0''; ++pointer) { if (*pointer == '','') {*pointer = ''\0'';s[i++] = pointer+1; } }assert(i<=MAXNUMENTRIES);s[i] = NULL; /* Signify end of valid entries */ puts("\n/* BEGIN output from new.c */\n");for (i=0; s[i] != NULL; i++)puts(s[i]); puts("\n/* END output from new.c */"); return 0; } 我但是没有测试它;只是想说清楚 怎么做:-) 干杯 Michael I did not test it, though; just wanted to make clearhow to do it :-)CheersMichael 这篇关于sscanf解析疑问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-19 10:19