UncleCoder.com

UncleCoder.com

Free programming examples and instructions

C program to study strlen() function

C program to study strlen() function

by Athil


Posted on 27 Jun 2018 Category: C Views: 43

Edited on 19 Jul 2019


C program to study strlen() function

The strlen() function calculates the length of a given string.  The function takes a single argument, i.e, the string variable whose length is to be found, and returns the length of the string passed.The strlen() function is defined in <string.h> header file. Below shows a sample program which uses the string function to find the length of a string

int main()
{
  char a[100];
  int length;
 
  printf("Enter a string :");
  gets(a);
 
  length = strlen(a);
 
  printf("Length of the string = %d\n", length);
 
  return 0;
}

 

OUTPUT



Leave a Comment: