温馨提示×

c语言怎么读取字符串长度

小亿
85
2024-07-27 02:52:08
栏目: 编程语言

在C语言中,可以使用strlen()函数来读取字符串的长度,即字符串中字符的个数(不包括字符串末尾的空字符’\0’)。

例如:

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

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

运行以上代码,输出结果为:

Length of the string: 13

注意:strlen()函数需要包含头文件string.h

0