函数题:求字符串长度
C语言标准函数库中包括 strlen 函数,用于求字符串的长度。作为练习,我们自己编写一个功能与之相同的函数。
#### 函数原型
c
int StrLen(const char *str);
说明:str 为串的起始地址,从该地址开始连续存储串中的字符,并以字符 '\0' 作为结束标记。函数值为串的长度,即串中字符(不包括结束标记)的总数。
#### 裁判程序
c
#include <stdio.h>
#include <string.h>
int StrLen(const char *str);
int main()
{
char s[1024];
int n;
gets(s);
n = StrLen(s);
printf("%d\n", n);
return 0;
}
/* 你提交的代码将被嵌在这里 */
#### 输入样例
in
abcd
#### 输出样例
out
4
答案:若无答案欢迎评论
#### 函数原型
c
int StrLen(const char *str);
说明:str 为串的起始地址,从该地址开始连续存储串中的字符,并以字符 '\0' 作为结束标记。函数值为串的长度,即串中字符(不包括结束标记)的总数。
#### 裁判程序
c
#include <stdio.h>
#include <string.h>
int StrLen(const char *str);
int main()
{
char s[1024];
int n;
gets(s);
n = StrLen(s);
printf("%d\n", n);
return 0;
}
/* 你提交的代码将被嵌在这里 */
#### 输入样例
in
abcd
#### 输出样例
out
4
答案:若无答案欢迎评论