#include<stdio.h>
#include<stdlib.h>
int main()
{
char str[999];
printf("PLEASE ENTER A STRING\n");
gets(str);//调用第二个头文件
int t=0,i=0,j=0,k=0;
int a[999];
char *p=str;
for(;*p!='\0';p++)
{
if(*p>='0'&&*p<='9')
{
t=t*10+(*p-'0');//将多个数串成字符串
k=1;//标识符,是1就写入数组
}
else//碰到下个不是数字,就把之前的数字存入数组
{
if(k==1)
{
a[j++]=t;
t=0;}
k=0;
}
}
if(k==1)
{a[j++]=t;}
a[j]='\0';
int *q=a;
printf("THERE ARE %d NUMBERS \n",j);
for(;*(q+i)!='\0';i++)
{
printf("%d ",*(q+i));
}
return 0;
}
编写过程参考过zyckhuntoria以及其他用户的回答,进行了简化和修改
附上前者链接https://blog.csdn.net/zyckhuntoria/article/details/79594482