这段 代码求解释啊
#include<stdio.h>
int main()
{
char str1[1000],*p1=str1;
int a[1000],*p2=a,ks=0,n=0,l,i;
gets(str1);
while(*p1++)
{
if(ks==0&&*(p1-1)>='0'&&*(p1-1)<='9')
ks=1;
if(ks==1&&(*(p1-1)<'0'||*(p1-1)>'9'))
ks=0;
if(ks&&*(p1-1)>='0'&&*(p1-1)<='9')
*p2++=*(p1-1)-'0';
if(ks&&(*(p1-1)>='0'&&*(p1-1)<='9')&&(*p1<'0'||*p1>'9'))
{
*p2++=10;
n++;
}
if(*p1==0)
*p2=*p1;
}
l=p2-a-1;
printf("%d\n",n);
for(i=0;i<l;i++)
a[i]==10? printf(" "):printf("%d",a[i]);
printf("\n");
return 0;
}
功能是 输入 673dd 6ssd23 输出673 6 23 并统计数目为3
------解决方案--------------------
C/C++ code
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
int main()
{
char str1[1000] = "673dd 6ssd23", *p1, *p2;
char buf[100] = {0};
int n=0;
p1 = str1;
p2 = str1 + strlen(str1);
while(p1 < p2 )
{
n = atoi(p1);
printf("p1 = [%s]\tn = %d\n", p1, n);
sprintf(buf, "%d", n);
p1 += strlen(buf);
while(!isdigit(*p1)) // 跳过非数字字符
p1++;
}
return 0;
}