c语言,求字符串的长度
时间: 2023-06-21 19:14:41 浏览: 204
在C语言中,可以使用标准库函数`strlen()`来获取字符串的长度。需要包含头文件`string.h`,函数原型如下:
```c
size_t strlen(const char *str);
```
其中,`str`为要计算长度的字符串,返回值为字符串的长度(不包括末尾的空字符'\0')。
示例代码:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "hello world";
int len = strlen(str);
printf("The length of \"%s\" is %d.\n", str, len);
return 0;
}
```
输出结果为:
```
The length of "hello world" is 11.
```
阅读全文
相关推荐













