在C语言中,可以使用标准库函数strlen()来获取字符串的长度。需要包含头文件<string.h>来使用这个函数。
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, World!";
int length = strlen(str);
printf("Length of the string: %d\n", length);
return 0;
}
上面的代码会输出字符串"Hello, World!"的长度为13。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: c语言输出中文乱码的原因有哪些