Write custom directory title here
Usage of strlen() in C language
Header file: #include <string.h>
The strlen() function is used to calculate the length of the string, and its prototype is: unsigned int strlen (char *s); s is the specified string
The function of strlen is to calculate the length of a string\that is, how many bytes
#include<stdio.h>
#include<string.h>
int main()
{
char *str1 = "1234567890123";
char str2[100] = "http://course.edu.cn/";
char str3[5] = "12345";
printf("strlen(str1)=%d, sizeof(str1)=%d\n", strlen(str1), sizeof(str1));
printf("strlen(str2)=%d, sizeof(str2)=%d\n", strlen(str2), sizeof(str2));
printf("strlen(str3)=%d, sizeof(str3)=%d\n", strlen(str3), sizeof(str3));
return 0;
}
If the number of characters is equal to the size of the character array, then the return value of strlen() cannot be determined, such as char str[3] = "abd", its return value is uncertain.