递归实现strlen函数
2014-04-13 15:49
651 查看
递归实现strlen函数,有点意思。
/*****************************************************************
code write : EOF
code date : 2014.04.13
e-mail : jasonleaster@gmail.com
code purpose:
This is a recursion way to implementate the strlen funciton.
******************************************************************/
#include <stdio.h>
int mystrlen(char * p_string)
{
if(*p_string == '\0')
{
return 0;
}
return mystrlen(++p_string)+1;
}
int main()
{
char * string = "hello world";
printf("The length of the string : %d\n",mystrlen(string));
return 0;
}
jasonleaster@ubuntu:~/Desktop$ ./a.out
The length of the string : 11
看到同样的问题,可以看看高手的blog。
http://blog.csdn.net/todd911/article/details/13774171
/*****************************************************************
code write : EOF
code date : 2014.04.13
e-mail : jasonleaster@gmail.com
code purpose:
This is a recursion way to implementate the strlen funciton.
******************************************************************/
#include <stdio.h>
int mystrlen(char * p_string)
{
if(*p_string == '\0')
{
return 0;
}
return mystrlen(++p_string)+1;
}
int main()
{
char * string = "hello world";
printf("The length of the string : %d\n",mystrlen(string));
return 0;
}
jasonleaster@ubuntu:~/Desktop$ ./a.out
The length of the string : 11
看到同样的问题,可以看看高手的blog。
http://blog.csdn.net/todd911/article/details/13774171
相关文章推荐
- C++递归实现strlen函数功能
- 自制函数实现strlen、strcpy、strcmp、strcat函数
- php实现无限级树型菜单(函数递归做法)
- 关于Oracle中split函数的实现以及函数递归的举例。
- 编写一个函数实现n^k,使用递归实现
- 编写一个函数reverse_string(char * string)(递归实现) 实现:将参数字符串中的字符反向排列。
- php递归实现无限分类生成下拉列表的函数
- 函数的strlen、memcpy、strcmp的实现
- 使用over函数实现递归汇总
- 递归和非递归实现strlen
- 函数和递归(组合数,孪生素数,用指针实现变量交换,求解二院一次方程组)
- 利用函数递归实现无限分类
- 使用函数递归实现基于php和MySQL的动态树型菜单
- sql 函数实现三种父子递归
- C语言:编写一个函数实现n^k,使用递归实现
- 数据结构之栈与递归的实现及应用(斐波拉契数列递归解法和strlen递归解法)
- 编写程序实现strlen()函数,strcmp(),strcpy(),strcat()的功能
- 部分函数的递归与迭代(非递归)实现
- 函数的调用机制_用递归实现栈(Function call machenism_Recursive calls stimulate stack)
- 编写一个函数reverse_string(char * string)(递归实现)