//:Vc++6.0 String strlen函数
//功能:求出字符串的长度
//参数:str 字符串
//返回值:返回字符串长度
#include<stdio.h>
int strlen(const char *str);
int main()
{
char *str = "hello";
printf("len = %d\n", strlen(str));
return 0;
}
int strlen(const char *str)
{
if (str == NULL)
{
perror("str");
return -1;
}
const char *temp = str;
while (*temp != '\0')
temp++;
return temp - str;
}
//在vc++6.0中的运行结果为:5
//返回值的大小不包括'\0'//:~
|