C语言怎么获取字符串长度
C语言怎样获得字符串长度
C语言中可使用strlen()函数来获得字符串长度。该函数需要一个字符串作为参数,返回值为该字符串的长度(不包括字符串末尾的'\0')。
例如:
```c
#include
#include
int main() {
char str[] = "Hello, world!";
int len = strlen(str);
printf("The length of the string is %d\n", len);
return 0;
}
```
输出结果为:
```
The length of the string is 13
```
文章来源:丸子建站
文章标题:C语言怎么获取字符串长度
https://www.wanzijz.com/view/74839.html