Easy Tutorial
❮ C Exercise Example20 C Function Strcspn ❯

C Library Function - strlen()

C Standard Library - <string.h>

Description

The C library function size_t strlen(const char *str) computes the length of the string str up to the null-terminating character, but not including it.

Declaration

Here is the declaration for the strlen() function.

size_t strlen(const char *str)

Parameters

Return Value

The function returns the length of the string.

Example

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

#include <stdio.h>
#include <string.h>

int main ()
{
   char str[50];
   int len;

   strcpy(str, "This is tutorialpro.org");

   len = strlen(str);
   printf("|%s| has a length of |%d|\n", str, len);

   return(0);
}

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

|This is tutorialpro.org| has a length of |18|

C Standard Library - <string.h>

❮ C Exercise Example20 C Function Strcspn ❯