How to calculate the length of a string in C language?
In the C language, the strlen() function can be used to determine the length of a string. This function takes a string as a parameter and returns the length of the string. An example is shown below:
#include <stdio.h>
#include <string.h>
int main() {
char str[50] = "Hello, World!";
int len = strlen(str);
printf("字符串的长度为:%d\n", len);
return 0;
}
The output result is:
字符串的长度为:13
The strlen() function is defined in the string.h header file.