Chinaunix首页 | 论坛 | 博客
  • 博客访问: 217710
  • 博文数量: 36
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 374
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-04 18:21
文章分类

全部博文(36)

文章存档

2011年(1)

2009年(5)

2008年(30)

我的朋友

分类: C/C++

2009-01-12 10:23:21

功能:在字符串中找出连续最长的数字串,并把这个串的长度返回,并把这个最长数字串付给其中一个函数参数outputstr所指内存。例如:"abcd12345ed125ss123456789"的首地址传给intputstr后,函数将返回9outputstr所指的值为123456789

 
#include
int Findmaxlen(char *input,char *output);
void main()
{
 char input[]="abc123def123456ee123456789dd";
 char output[50]={0};
 int maxlen;
 maxlen=Findmaxlen(input,output);
 printf("the str %s\n",output);
 printf("the maxlen is %d \n",maxlen);
}
int Findmaxlen(char *input,char *output)
{
 char *in=input,*out=output,*temp,*final;
 int count=0,maxlen=0,i;
 while(*in!='\0')
 {
  if(*in>='0'&&*in<='9')
  {
   count=0;
   for(temp=in;*in>='0'&&*in<='9';in++)
    count++;
   if(maxlen   {
    maxlen=count;
    final=temp;   
   }//if 
  }//if
  in++;
 }//while
 for(i=0;i  *out++=*final++;
 *out='\0';
 return maxlen;
}
 
阅读(4393) | 评论(0) | 转发(1) |
0

上一篇:僵尸进程

下一篇:将数字转化成字符串

给主人留下些什么吧!~~