×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
compare two string - String
Find the length of a string - String - String - C Language
2816    Arnab De    13/04/2019

Find the length of a string

To find out the length of a string, we follow the following step -

  1. Declare a counter variable with default value 0
  2. Read the String
  3. Travel the string, until the '\\0' character return.
  4. Print the counter value as string length
int main()
{
	char str[30],i,cnt=0;
	printf("Enter A String: ");
	gets(str);
	for(i=0;str[i]!='\0';i++)
	{
		cnt++;
	}
	printf("Length of the string is %d",cnt);
	return 0;
}
softetechnologies
compare two string - String
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Sri Sri Ramakrishna Paramahamsa
Have love for everyone, no one is other than you.
Sri Sri Ramakrishna Paramahamsa
2515
81.09
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54173
25/06/2018     45158
01/01/2018     43708
28/06/2017     41235
02/08/2017     40259
01/08/2017     34302
06/07/2017     34096
15/05/2017     33353
11/09/2018     30370
14/07/2017     29870
softetechnologies