Sunday, 15 November 2015

C++ Program to Find The Length of a String Without Using Strlen Function

Problem:- Write A C++ Program To Find The Length Of Any String or How to Find the length of String In C and C++? or C++ Program to Find Length of String Without Using Library Function or C++ program to find Length of String or C++ Program to Find the Length of a String or C++ program to Find Length of String without using strlen or calculate length of a string without using standard library or C program to find the length of a String without using function strlen() or Returning number of characters without using strlen or C Program to Find the Length of a String without using the Built-in function or Program to find the length of a string taken from user without using inbuilt function.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Logic:- We have an inbuilt function to find length or size of the string. In this problem, I count string character from start to end ( '\0' ) and print the total number of count. we can either use a count variable and increase the count by 1 in each iteration but no need I an using an array index and with the help of an array I print the last index of an array. we can calculate a length of a string in C/C++ both functions are given below.

Length of String In C

strlen(str)


Length of String In C++

str.size();
str.length() c++

Both Use in C++. Here str is a string variable.

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page.


Solution:-


#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
 int main()
{
/*Visit - www.programmingwithbasics.com*/
   
    cout<<"=====================================";
    cout<<"\nVisit - www.programmingwithbasics.com";
    cout<<"\n=====================================";
    
  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:-

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment