Thursday, 20 September 2012

String length


This program prints length of string, for example consider the string "c programming" it's length is 13. Null character is not counted when calculating string length. To find string length we use strlen function of string.h.

C program to find string length

#include<stdio.h>
#include<string.h>
 
main()
{
   char a[100];
   int length;
 
   printf("Enter a string to calculate it's length\n");
   gets(a);
 
   length = strlen(a);
 
   printf("Length of entered string is = %d\n",length);
 
   return 0;
}

No comments:

Post a Comment