前言
编写函数求给定字符串的长度。
函数接口定义:
int mystrlen ( const char *s);
其中 s 是一个以空字符结尾的字符串。函数返回该字符串的长度,即字符串中所包含的字符个数(不含结尾的空字符)。
裁判测试程序样例:
#include <stdio.h>
int mystrlen ( const char *s);
int main()
{
char str[256];
gets(str);
printf("%d", mystrlen(str));
return 0;
}
/* 你的答案将出现在这里 */
/* 你的代码将被嵌在这里 */
输入样例:
hello world
输出样例:
11
输入你的答案
int mystrlen ( const char *s){
int i=0,n=0;
while(s[i]!='\0'){
n++;i++;
}
return n;
}