#include <iostream>
using namespace std;
int main()
{
int statistic(char *,int *);
char str[50],*pstr;
int a[10],*pa,len;
int m=0;
pstr=str;
pa=a;
cout<<"please input a string:";
gets(str);
cout<<endl;
len=strlen(str);
cout<<"the length of the string is:"<<len<<endl;
m=statistic(pstr,pa);
cout<<"the number of the integer is:"<<m<<endl;
cout<<"the integer are(is): "<<endl;
for(int n=0;n<m;n++)
{
cout<<*(pa+n)<<" ";
}
cout<<endl;
return 0;
}
int statistic(char *pstr,int *pa)
{
int i=0; //i代表字符串中的第几个字符
int j=0; //j代表连续数字的个数
int count=0; //count代表有多少个整数
int digit,k,e10,m;
while(*(pstr+i)!='\0')
{
if(*(pstr+i)>='0' && *(pstr+i)<='9')
{
j++;
}
else
{
if(j>0)
{
digit=*(pstr+i-1)-48; //将个数位赋予digit
k=1;
while(k<j) //将含有两位以上数的其它位的数值累计于digit
{
e10=1;
for(m=0;m<k;m++)
{
e10=e10*10; //e10代表该位数所应乘的因子
}
digit=digit+(*(pstr+i-1-k)-48)*e10; //将该位数的数值累加于digit
k++; //位数k自增
}
*pa=digit; //将数值放在数组a中
count++;
pa++; //指针pa指向a数组下一元素
j=0;
}
}
i++;
}
if(j>0) //以数字结尾字符串的最后一个数据
{
digit=*(pstr+i-1)-48;
k=1;
while(k<j)
{
e10=1;
for(m=0;m<k;m++)
{
e10=e10*10;
}
digit=digit+(*(pstr+i-1-k)-48)*e10;
k++;
}
}
*pa=digit;
count++;
j=0;
return count;
}
using namespace std;
int main()
{
int statistic(char *,int *);
char str[50],*pstr;
int a[10],*pa,len;
int m=0;
pstr=str;
pa=a;
cout<<"please input a string:";
gets(str);
cout<<endl;
len=strlen(str);
cout<<"the length of the string is:"<<len<<endl;
m=statistic(pstr,pa);
cout<<"the number of the integer is:"<<m<<endl;
cout<<"the integer are(is): "<<endl;
for(int n=0;n<m;n++)
{
cout<<*(pa+n)<<" ";
}
cout<<endl;
return 0;
}
int statistic(char *pstr,int *pa)
{
int i=0; //i代表字符串中的第几个字符
int j=0; //j代表连续数字的个数
int count=0; //count代表有多少个整数
int digit,k,e10,m;
while(*(pstr+i)!='\0')
{
if(*(pstr+i)>='0' && *(pstr+i)<='9')
{
j++;
}
else
{
if(j>0)
{
digit=*(pstr+i-1)-48; //将个数位赋予digit
k=1;
while(k<j) //将含有两位以上数的其它位的数值累计于digit
{
e10=1;
for(m=0;m<k;m++)
{
e10=e10*10; //e10代表该位数所应乘的因子
}
digit=digit+(*(pstr+i-1-k)-48)*e10; //将该位数的数值累加于digit
k++; //位数k自增
}
*pa=digit; //将数值放在数组a中
count++;
pa++; //指针pa指向a数组下一元素
j=0;
}
}
i++;
}
if(j>0) //以数字结尾字符串的最后一个数据
{
digit=*(pstr+i-1)-48;
k=1;
while(k<j)
{
e10=1;
for(m=0;m<k;m++)
{
e10=e10*10;
}
digit=digit+(*(pstr+i-1-k)-48)*e10;
k++;
}
}
*pa=digit;
count++;
j=0;
return count;
}