Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4733916
  • 博文数量: 930
  • 博客积分: 12070
  • 博客等级: 上将
  • 技术积分: 11448
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-15 16:57
文章分类

全部博文(930)

文章存档

2011年(60)

2010年(220)

2009年(371)

2008年(279)

分类: C/C++

2008-11-14 18:38:28

   当时这到题,真的想了好久,大家别鄙视我哈.某次看ds的stack与递归的时候,我靠...递归不就OK了吗^_^不用你们鄙视我,我自己先鄙视下自己.
   

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int count_str (char *);
int
main ()
{
  char *str = (char *) malloc (sizeof (char) * 100);
  printf ("Please input the string you want to count:\n");
  fgets (str, 100, stdin);
  printf ("The length of %s is mycount=%d,strlen=%d\n", str, count_str (str),
     strlen (str));

  return 0;
}

int
count_str (char *string)
{
  if (*string == '\0')
    return 0;
  else
    return (1 + count_str (++string));
}

 gcc -o strlen strlen.c
 ./strlen
 Please input the string you want to count:
 this is a
 The length of this is a
 is mycount=16,strlen=16

看起来都很简单,可是真在那种环境下,还是很白痴的,

阅读(1158) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~