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:-
You May Also See
1. C Program To Display Size Of Different Datatype
2. C Program To Check Number Is Positive Or Negative
3. C Program To Find Character Is Vowel Or Not
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:-
You May Also See
1. C Program To Display Size Of Different Datatype
2. C Program To Check Number Is Positive Or Negative
3. C Program To Find Character Is Vowel Or Not
0 Comments: