递归实现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