Linux 拨号vps windows公众号手机端

c语言中计算字符串长度的函数

lewis 8年前 (2017-04-17) 阅读数 9 #程序编程
文章标签 c语言

在C语言中,可以使用strlen函数来计算字符串的长度。

strlen函数的原型为:size_t strlen(const char *str)

其中,str是一个指向以null (‘\0’) 字符结尾的字符串的指针。

示例代码如下所示:

#include <stdio.h>
#include <string.h>

int main() {
    char str[] = "Hello, world!";
    int length = strlen(str);
    printf("The length of the string is: %d\n", length);
    return 0;
}

输出结果为:The length of the string is: 13

版权声明

本文仅代表作者观点,不代表米安网络立场。

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

热门