How to use the strlen function in C language?
The strlen function is used to calculate the length of a string, and its declaration is as follows:
size_t strlen(const char *str);
其中,str是一个指向字符串的指针,函数返回字符串的长度,不包括字符串末尾的空字符’\0’。
Here is how to use it:
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, World!";
size_t len = strlen(str);
printf("字符串的长度为:%zu\n", len);
return 0;
}
The output is: the length of the string is 13.