Programming Examples
Cpp program to input name and find the length of the stored string
Write a program to input name and find the length of the stored string
Solution
#include <iostream>
using namespace std;
int main()
{
char name[20];
int a;
cout << "Enter your name : ";
cin.getline(name,20);
int len = 0;
for (a = 0; name[a] != '\0'; a++)
{
len++;
}
cout << "Length of the string is: " << len;
return 0;
}
Output
Enter your name : Infomax Academy
Length of the string is: 15