int findMaxNumLength(char *str)
{
int max = 0;
int count = 0;
char* index = str;
while(*index != '\0')
{
if(*index >='0' && *index <='9')
{
count++;
}
else
{
if(count > max)
{
max = count;
}
//遇到非数字字符,都需要将count置为0
count = 0;
}
index++;
}
return max;
}
思路是,遇到一个数字,count++。遇到非数字字符时,比较count和max的大小,然后将count赋值为0.