给定一个字符串,输出字符串中最长的数字串,并把这个数字串的长度输出

如题所述

#include <stdio.h>
#include <string.h>
void main()
{
char str[100]="as123Adf324324sgfd889ASD9992347j123";
char num[20]={0},tmp[20]={0};
int i=0,tl=0,len=0;
for (i=0;str[i]!='\0';i++)
{
if (str[i]>='0' && str[i]<='9')
{
tmp[tl++] = str[i];
}else
{
tmp[tl]='\0';
if (tl>len)
{
len = tl;
strcpy(num,tmp);
}
tl=0;
}
}
printf("the Max len is [%s][%d]\n",num,len);
}

the Max len is [9992347][7]
Press any key to continue

温馨提示:答案为网友推荐,仅供参考
相似回答