C语言|找出字符串中找出连续最长的数字串代码实现及思路

#include
#include#define DU 100 int continumax(char *outtstr,char *intstr);
int main()
{
char instr[1024];
char outstr[1024];
int len = 0;
printf("please input string!\n");
scanf("%s",instr);
printf("you input str is %s\n",instr);
len = continumax(outstr,instr);
printf("the result is %s\n the lenth is %d,\n",outstr,len);
return 0;
} int continumax(char *outtstr,char *intstr)
{
int len = 0;
int maxlen = 0;
int i = 0;
char *in = intstr;
while(*in != '\0')
{
while(*in >= '0' && *in <= '9')
{
len++;
in++;
}
if(len > maxlen)
{
maxlen = len;
in = in - len;
for(i = 0; i< maxlen; i++)
{
outtstr[i] = *(in+i);
}
outtstr[maxlen] = '\0';
in = in + len - 1;
len = 0; //很重要
}
in++;
len = 0;
}
return maxlen;
}

    推荐阅读