6-6 '字符串01-字符串长度(10 分)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_41611106/article/details/82595099

C语言标准函数库中包括 strlen 函数,用于计算字符串的长度。作为练习,我们自己编写一个功能与之相同的函数。
函数原型

// 字符串长度
int StrLen(const char *str);

说明:str为串的起始地址,函数值为字符串的长度(不含结束标记’\0’)。
裁判程序

#include <stdio.h>
// 字符串长度
int StrLen(const char *str);
int main()
{
    char a[1024];
    int n;
    gets(a);
    n = StrLen(a);
    printf("%d\n", n);
    return 0;
}

/* 你提交的代码将被嵌在这里 */

输入样例

abcd

输出样例:
4

int StrLen(const char *str)
{
    int count;
    int len;
    len=strlen(str);
    return len;
} 

猜你喜欢

转载自blog.csdn.net/qq_41611106/article/details/82595099