您的位置:首页 > 其它

递归实现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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: