Free programming examples and instructions

C find the length of string using 'strlen()' function

C program to find the length of a string using strlen() function

by Krishna viswambharan

Posted on 27 Sep 2017 Category: C Views: 259

Edited on 11 Oct 2017

C program to study 'strlen()'  function

In this article we will see the string functions.  Here we will see how to find the length of a string using ‘strlen’ function.  This string function is defined in the <string.h> header file.

strlen( ) function in C gives the length of the given string. Syntax for strlen( ) function is given as follows:-

strlen ( const char * string );

In the below program the length of the entered string is computed using the strlen() function. 

#include <stdio.h>
#include <string.h>
#include <conio.h>
void main()
   char a[100];
   int length;
   printf("Enter the string :");
   gets(a);  //read string
   length = strlen(a);  //compute length
   printf("length of entered string  = %d",length);


Leave a Comment: