How do you determine the length of a string in the C language?
In C language, the strlen() function from the standard library can be used to calculate the length of a string. This function is located in the string.h header file. strlen() takes a string as a parameter and returns the length of the string, excluding the null character ‘\0’ at the end of the string.
Here is an example of using the strlen() function:
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "Hello, World!";
int len = strlen(str);
printf("字符串的长度是:%d\n", len);
return 0;
}
The output is: the length of the string is 13.