|
#include <stdlib.h> /* 功能:在字符串中找出连续最长的数字串,并把这个串的长度返回 返回值: */ int MaxLen=0; char *temp = (char*)malloc((MaxLen+1)* sizeof(char)); |
|
| 40分 |
unsigned int Continumax(char** ppout, char* src)
{
char *last=NULL;
int ans=0;
for(;*src;++src){
if(isdigit(*src)){
if(!last) last =src;
}else{
if(last&&src-last>ans){
*ppout =last;
ans =src-last;
last =NULL;
}
}
}
if(last && src-last>ans)
{
*ppout =last;
ans =src-last;
}
return ans;
}
|
|
自己顶一下~
Maxlen结果正确,但是赋值不对~ |
|
|
错误应该在这部分
char *temp = (char*)malloc((MaxLen+1)* sizeof(char)); for (i=0;i<MaxLen;i++) { temp[i]=intputstr[begin+i]; //不改变outputstr地址 } temp[MaxLen]=””\0″”; //Ptr=Ptr-maxLen; *pOutputstr=temp; return MaxLen; } |
|
|
咨询了下,同学不是指针的错误~前面的表达有欠妥当,把源码粘出来
#include <stdlib.h> /* 功能:在字符串中找出连续最长的数字串,并把这个串的长度返回 返回值: */ int MaxLen=0; char *temp = (char*)malloc((MaxLen+1)* sizeof(char)); |
|