5,530
社区成员
发帖
与我相关
我的任务
分享
//有字符串
//1_22_333,,4444__55555,_666666
//需要解析为
//1
//22
//333
//_
//4444
//55555
//666666
#include <stdio.h>
char s[]="1_22_333,,4444__55555,_666666";
char c,*p,*p1;
int st;
void main() {
st=0;
p=s;
while (1) {
c=*p;
if (0==c) {
switch (st) {
case 1:printf("_\n"); break;
case 2:printf("%s\n",p1);break;
}
break;//
}
switch (st) {
case 0:
if ('_'==c) { st=0;}
else if (','==c) { st=1;}
else {p1=p; st=2;}
break;
case 1:
if ('_'==c) { st=1;}
else if (','==c) {printf("_\n"); st=1;}
else {p1=p; st=2;}
break;
case 2:
if ('_'==c) {*p=0;printf("%s\n",p1);*p=c;st=0;}
else if (','==c) {*p=0;printf("%s\n",p1);*p=c;st=1;}
else { st=2;}
break;
}
p++;
}
}
//1
//22
//333
//_
//4444
//55555
//666666