在字符串中找出连续最长的数字串
写一个函数,它的原形是int continuemax(char*outputstr,char*inputstr)功能:在字符串中找出连续最长的数字串并把这个串的长度返回,并把这个最长数字串付给其中一个函数参数outputstr所指内存。例如:“abcd12345e123456789d125ss”的首地址传给intputstr后,函数将返回9,outputstr所指的值为123456789.
#include
using namespace std;
int continuemax(char* outputstr,char* inputstr)
{
int max=0;
//字符串中连续最长的数字串长度
int cnt;
//记录连续数字字符的个数
char* tmp0=NULL;
char* tmp1=NULL;
int i;
for(;
;
)
{
while(*inputstr != 0 && (*inputstr > '9' || *inputstr < '0'))//跳过非数字字符
++inputstr;
cnt = 0;
//必须清零
tmp0=inputstr;
while(*inputstr != 0 && (*inputstr >= '0' && *inputstr <= '9'))//检测数字字符
{
++cnt;
++inputstr;
}
if(cnt > max)
{
max=cnt;
tmp1=tmp0;
//tmp1指向连续数字字符最长的首地址
}
if(*inputstr == 0) //字符串结束后跳出循环
break;
}
for(i=0;
i
推荐阅读
- 热闹中的孤独
- 你到家了吗
- Shell-Bash变量与运算符
- JS中的各种宽高度定义及其应用
- 闲杂“细雨”
- 杜月笙的口才
- 2021-02-17|2021-02-17 小儿按摩膻中穴-舒缓咳嗽
- 深入理解Go之generate
- 赢在人生六项精进二阶Day3复盘
- 祖母走了