C-programming - Length of a string, C program to find length of a string

Length of a string

This program counts the number of letters in input string. Here gets function is used to get input. But scanf can also be used to get string at run time.
Here a count variable is been intialised to zero to count the letters in the string. If condition is checked and the count value is incremented.

#include<stdio.h>
#include<conio.h>
int main()
{
int i,count=0;
char a[100];
printf("enter the string
");
gets(a);
for(i=0;i<strlen(a);a++)
{
if(a[i]!=0)
count=count+1;
}
printf("
length of the string is %d ",count);
getch();
}


output


enter the string
I LOVE INDIA
length of the string is 10

The topic on C-programming - Length of a string is posted by - Math

Hope you have enjoyed, C-programming - Length of a stringThanks for your time

Tech Bluff