按指定字符分割字符串!
本帖最后由 Cool_Breeze 于 2020-3-7 17:39 编辑#include <stdio.h>
int main(void)
{
char sum={"0"};
char res={"0"};
int j=0,k=0;//sum j第二维的下标,k第一维的下标
int i=0,count=0;//count计数
char *p=sum;
gets(sum);
for (;*p;p++)
{
switch (*p)
{
case ',':
count++,j++,k=0;
break;
default :
res=*p;
}
}
if (i > 0)
for (i=0;i<=count;i++) printf("%-3d:%30s\n",i+1,res);
printf("%s\n",__TIME__);
return 0;
}
Cool_Breeze,C,o,o,l,_,B,r,e,e,z,e,
1: Cool_Breeze
2: C
3: o
4: o
5: l
6: _
7: B
8: r
9: e
10 : e
11 : z
12 : e
13 :
17:27:58
--------------------------------
Process exited after 63.84 seconds with return value 0
请按任意键继续. . .
页:
[1]