1.数组:
#include<stdio.h>
int strlen(char s[])
{
int i = 0;
while(s[i] != ‘\0‘)
{
i++;
}
return i;
}
2.指针:
#include<stdio.h>
int strlen(char *p)
{
int len = 0;
while(*p)
{
count++;
}
return count;
}
3.递归:
#include<stdio.h>
int strlen(char *p)
{
if(!(*p))
{
return 0;
}
else
{
return 1 + strlen(p+1);
}
}本文出自 “水仙花” 博客,请务必保留此出处http://10704527.blog.51cto.com/10694527/1708948
原文:http://10704527.blog.51cto.com/10694527/1708948