Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Library Function – strlen()

C Library Function - strlen()

C Standard Library - <string.h> C Standard Library -

Description

C Library Function **size_t strlen(const char *str) ** computes the length of the string str up to the null terminator, but not including the null terminator.

Declaration

Below is the declaration of the strlen() function.



size_t strlen(const char *str)

Parameters

Return Value

This function returns the length of the string.

Example

The following example demonstrates the use of the strlen() function.



#include 

#include 



int main ()

{

   char str[50];

   int len;



   strcpy(str, "This is runoob.com");



   len = strlen(str);

   printf("|%s| 的长度是 |%d|\n", str, len);

   

   return(0);

}

Let's compile and run the above program, which will produce the following result:



|This is runoob.com| 的长度是 |18|

C Standard Library - <string.h> C Standard Library -