strlen : <string.h> library function

The function size_t strlen(const char *str);calculates the length of a string. The length of a C string is the number of character before terminating null character('\0').

Function prototype of strlen

size_t strlen(const char *str);
  • str : This is the string whose length is to be found.

Return value of strlen

This function returns the length of string.

C program to show the use of strlen function

The following program shows the use of strlen function to find the length of string.

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

int main()
{
   char string[100];
   int length;
   
   printf("Enter a string\n");
   scanf("%s", &string);
   
   length = strlen(string);

   printf("Length of %s is %d", string, length);
   
   getch();
   return(0);
}

Program Output
Enter a string
TechCrashCourse
Length of TechCrashCourse is 15