在C语言中,可以使用strlen函数来计算字符串的长度。strlen函数定义在<string.h>头文件中。

下面是一个示例代码:

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

int main()
{
    char str[] = "Hello, World!";
    int len = strlen(str);
    printf("字符串的长度是:%d\n", len);
    
    return 0;
}

输出结果为:

字符串的长度是:13

在上面的例子中,我们使用了strlen函数来计算字符串"Hello, World!"的长度。然后将结果打印出来。

c语言计算字符串长度

原文地址: https://www.cveoy.top/t/topic/ihUH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录