Sunday, 15 November 2015

C++ Program To Find The Length Of String

Problem :- Write A C++ Program To Find The Length Of Any String

Logic :- How to Find length of String In C and C++ ?

We Have inbuilt function to find length of String Example are giver below
Length In C 

strlen(str)

Length In C++  

str.size();
str.length() c++
Both Use in C++.

In this problem i Count string Character from Start to End ( '\0' ) and print the count .

Solution :-

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
 int main()
{
//By-Ghanendra Yadav
  char a[50];
  int i;
 
  cout<<"Enter An Any  String:\t";
  gets(a);
  for(i=0;a[i]!='\0';++i)
  {
 
  }
  cout<<"\nLenth Of The Given String Given Below Is\n\n";
  cout<<i<<endl;
 return 0;
}

Output:-

C++ Program To Find The Length Of String

No comments:
Write comments

Recommended Posts × +