文档库 最新最全的文档下载
当前位置:文档库 › 识别字符串中的整数并转换为数字形式

识别字符串中的整数并转换为数字形式

#include
#include
#include
using namespace std;

void take_num(const char *strIn,int *n,unsigned int *outArray)
{
int len=strlen(strIn);
//int len1;
int *m=NULL;
int sum=0;
int count=0;
char *strTemp=NULL;
int s;
strTemp=new char[len+1];
char *pos=strTemp;
int i;
for(i=0;i{
if(isdigit(strIn[i]))
{
*pos++=strIn[i];
s=0;
}
else
{
if(s==1)
{
continue;
}
*pos++='a';
s=1;
}
}
*pos='\0';
// cout<len=strlen(strTemp);
for(i=0;i{
if(strTemp[i]=='a')
{
if(i==0)
{
continue;
}
else
{
outArray[count]=sum;
count++;
sum=0;
}
}
else
{
sum=sum*10+(strTemp[i]-'0');
}
}
n=&count;
cout<<"n="<<*n<cout<<"转换后的整数为:"<for(i=0;i{
cout<}
cout<delete strTemp;
strTemp=NULL;
}

int main()
{
const char *strIn="ab0001cd+123fght456-25 3.005fgh";
int *n=NULL;
unsigned int *outArray;
outArray=new unsigned int[strlen(strIn)*4] ;
take_num(strIn,n,outArray);
delete outArray;
outArray=NULL;
return 0;
}






相关文档
相关文档 最新文档