2008/11/01
| |
不使用中间变量实现strlen函数,(strlen为c语言里面求字符串长度库函数)。给出了一个函数声明:
int strlen(const char *p);

#include<iostream.h>
int strlen_my(const char *p);
void main()
{  
    const char *p="wenxueba.net";
    int length=strlen_my(p);
cout<<length<<endl;
}  
int strlen_my(const char *p)
{
if(p==NULL)
    {
        return 0;
    }
    if(*p=='\0')
    {
        return 0;
    }
    else  
        return 1+strlen_my(++p);
}
不指定 2008/11/01 14:31, wxxslt, 网站建设 » C/C++, 评论(0), 阅读(4811)
发表评论
表情
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]
               

 
Theme by Marshal. Powered by Bo-Blog 2.1.1 ReleaseCode detection by Bug.Center.Team