int chompnum(char* str, char** to)
{
int dig = 0;
int num = 0;
while (*str)
{
if (*str >= '0' && *str <= '9')
{
dig++;
}
else if (dig)
{
to[num] = (char*) malloc(dig + 1);
memcpy(to[num], str-dig, dig);
to[num][dig] = 0;
num++;
dig = 0;
}
str++;
}
if (dig)
{
to[num] = (char*) malloc(dig + 1);
memcpy(to[num], str - dig, dig);
to[num][dig] = 0;
num++;
dig = 0;
}
return num;
}
int main()
{
char a[] = "a123x456,1768?0302tab5876";
char* b[50];
int i = 0;
int num = chompnum(a, b);
printf("%d\n", num);
while (i < num)
{
printf("%s\n", b[i]);
free(b[i]);
i++;
}
return 0;
}
#include
using namespace std;
int main()
{
int a[50]={0},sum=0,i,j=0;
char str[200]={0};
cin.getline(str,200);
for(i=0;i<=200;i++)
{
if(str[i]>='0'&&str[i]<='9')
sum=sum*10+str[i]-48;
else
{
if(sum)a[j++]=sum;
sum=0;
}
}
for(i=0;ireturn 0;
}
是数字就存入其他不存入吗?