写一个函数,它的原形是int continumax(char *outputstr,char*intputstr)功能:在字符串中找出连续最长的数字串,并把这个串的长度返回,并把这个最长数字串付给其中一个函数参数outputstr所指内存。例如:"abcd12345ed125ss123456789"的首地址传给intputstr后,函数将返回9,outputstr所指的值为123456789
#include <stdio.h>
int counterMax(char **outputstr, char *inputStr)
{
int max = 0;
while(*inputStr != '\0')
{
while(*inputStr < '0' || *inputStr > '9')
{
inputStr++;
if('\0' == inputStr)
goto END;
}
char *tmpStr = inputStr;
while((*inputStr >= '0') && (*inputStr <= '9'))
{
inputStr++;
if('\0' == inputStr)
goto END;
}
if(inputStr - tmpStr > max)
{
max = inputStr - tmpStr;
*outputstr = tmpStr;
}
}
END:
return max;
}
int main(void)
{
char input[] = "abcd12345ed125ss123456789";
char *output = NULL;
printf("max = %d\n", counterMax(&output, input));
printf("output = %s\n", output);
return 0;
}