void main()
{
char a[80],*p=a;
int b[80]={0},i=0,j=0,x=0; //!!!!
printf("请输入一串字符\n");
gets(a);
for(p=a;(*p)!='\0';p++)
{
if(((*p)>='0')&&((*p)<='9')) //!!!!
{
if(x==0)
{
b[i]=(*p)-48;
i++;
}
else
b[i-1]=b[i-1]*10+(*p)-48;
x=1;
}
else
x=0;
}
for(j=0;b[j]!=0;j++) //!!!!
printf("%d ",b[j]);
printf("共有%d个",j);
printf("\n");
}
#include
#include
int main(int argc, char* argv[])
{
const char str[256] = "sd348ghi 35qeaio843ud843";
char sNumbers[32][32];
int i = 0, j = 0, k = 0;
int len = strlen(str);
int bNumber = 0;
while (i < len)
{
bNumber = 0;
while ((str[i] < '9') && (str[i] > '0'))
{
bNumber = 1;
sNumbers[j][k++] = str[i++];
}
if (bNumber)
{
sNumbers[j][k++] = '\0';
j++;
bNumber = 0;
}
i++;
k = 0;
}
printf("Count: %d\n", j);
for (i = 0; i
getch();
return 0;
}
#include
#include
void main()
{
char str[1024];
char *p;
int a[64];
int n = 0;
int i;
printf("please input: ");
gets(str);
for(p = str; *p != '\0'; p++)
{
if (*p >= '0' && *p <= '9')
{
a[n++] = atoi(p);
for(++p; *p >= '0' && *p <= '9'; p++);
}
}
printf("total %d integer(s).\n", n);
for(i = 0; i < n; i++)
{
printf("%d\n", a[i]);
}
}
定义一个足够的数组,循环字符数组,遇到数字就放到新的数组中
~~~~~~~~~~