#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef unsigned char u8;
typedef unsigned int u16;
typedef char s8;
typedef int s16;
#if 1
/*********************************************
-在字符串中找到连续递增最长的数字字符串
- parameter1: 输入字符串首地址
parameter2: 输出寻找结果字符串的首地址
*********************************************/
u16 continuemax(u8 *instr, u8 **outstr)//要修改某个指针的指向位置,需要地址传递,即¶meter2
{
u16 len=0;
u16 i,j;
if(instr==NULL)
return 0;
*outstr =NULL;//如果没找到,则返回指针指向空
for(i=0;i<strlen((const char *)instr);i++)
{
if(instr[i]>='0' && instr[i]<='9')
{
j=0;
while(1)
{
if((instr[i+j+1]>='0'&& instr[i+j+1]<='9')&&
(instr[i+j+1] > instr[i+j]))
j++;
else
{
if(len<j)
{
len=j+1;
*outstr = &instr[i];
}
break;
}
}
i+=j;
}
}
return len;
}
void myprintf(u8 *str, u16 len)
{
u16 i=0;
while(len--)
{
printf("%c",str[i++]);
}
printf("\n");
}
void main()
{
//u8 instr[100];//方法一
u8 *instr=(u8*)malloc(100);//方法二
u8 *outstr;
u8 len=0;
while(1)
{
printf("please input a string:\n");
scanf("%s",instr);
len =continuemax(instr,&outstr);//要修改某个指针的指向位置,需要地址传递,即¶meter2
myprintf(outstr,len);
}
free(instr);方法二
instr=NULL; 方法二
}
#endif
/*
运行结果:
please input a string:
sd123seerd345676fgh56258953
34567
please input a string:
123456ghgh9876456hj
123456
please input a string:
1d3fg45678fg0356789gh
0356789
please input a string:
*/