C language strlen () function: Returns the length of a string
Header files: #include <string.h>
The strlen () function is used to calculate the length of a string, and its prototype is: unsigned int strlen (char *s); s for the specified string
eg
#include <stdio.h> #include <string.h>int main () { char *str1 = "http://see.xidian.edu.cn/cpp/u/shipin/"; Char str2[100] = "http://see.xidian.edu.cn/cpp/u/shipin_liming/"; 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;}
Operation Result:
Strlen (str1) =38, sizeof (STR1) =4
Strlen (str1) =45, sizeof (STR1) =100
Strlen (str1) =53, sizeof (STR1) =5
if the number of characters equals the size of the character array, then the return value of strlen () cannot be determined , for example
Char str[6] = "ABCXYZ";
The return value of strlen (str) will be indeterminate. Because the end of STR is not 0,strlen () will continue to retrieve backwards until it encounters ' \ ' and the contents of these areas are indeterminate.
C language strlen () function usage