咨询了下,同学不是指针的错误~前面的表达有欠妥当,把源码粘出来
#include
#include”string”
using namespace std;
#include “oj.h”
/* 功能:在字符串中找出连续最长的数字串,并把这个串的长度返回
函数原型:
unsigned int Continumax(char** pOutputstr, char* intputstr)
输入参数:
char* intputstr 输入字符串
输出参数:
char** pOutputstr: 连续最长的数字串,如果连续最长的数字串的长度为0,应该返回空字符串
pOutputstr 指向的内存应该在函数内用malloc函数申请,由调用处负责释放
返回值:
连续最长的数字串的长度
*/
unsigned int Continumax(char** pOutputstr, char* intputstr)
{
int Len=strlen(intputstr);
if (*intputstr==NULL || Len==0)
{
*pOutputstr=””;
return 0;
}
int MaxLen=0;
int wordLen=0;
int i,j,begin=0;
int flag[200];
for (i=0;intputstr[i]!=””\0″”;i++) //判断字符是否为数字
{
if (intputstr[i]>=””0″” && intputstr[i]<=””9″”)
flag[i]=1;
else flag[i]=0;
}
for (i=0;intputstr[i]!=””\0″”;)
{
if (flag[i]==1)
{
for(j=i;flag[j]==1 && intputstr[j]!=””\0″”;j++) //获得数字串的长度wordLen
wordLen++;
if (wordLen>=MaxLen)
{
MaxLen=wordLen;
begin=i;
}
i=i+wordLen;
}
else
i++;
wordLen=0;
}
char *temp = (char*)malloc((MaxLen+1)* sizeof(char));
for (i=0;i
{
temp[i]=intputstr[i+begin]; //不改变outputstr地址
}
temp[MaxLen]=””\0″”;
//Ptr=Ptr-maxLen;
*pOutputstr=temp;
return MaxLen;
}