+ 3

How to take user input for character array

I wrote a program to calculate length but when I use cin.get (name, size) it gives output length as 0 in the for loop I used the condition till I is not equal to '\0'

8th Mar 2017, 12:20 PM
Suparna Chakraborty
Suparna Chakraborty - avatar
6 Answers
+ 2
c++
8th Mar 2017, 2:20 PM
Suparna Chakraborty
Suparna Chakraborty - avatar
+ 2
#include <iostream> using namespace std; int main() { string name; getline(cin,name); cout<<"You entered the name: "<<name; return 0; } try the above code suparna u will get it
8th Mar 2017, 3:33 PM
Sachin Yadav
Sachin Yadav - avatar
+ 2
#include <iostream> using namespace std; int main() { string name; getline(cin,name); cout<<"You entered the name: "<<name<<endl; int l=name.length(); cout<<"number of character="<<l; return 0; }
8th Mar 2017, 3:51 PM
Abhishek kumar tantia
Abhishek kumar tantia - avatar
+ 1
in which lang, u have written the code
8th Mar 2017, 1:02 PM
Abhishek kumar tantia
Abhishek kumar tantia - avatar
+ 1
#include <iostream> using namespace std; int main() { string name; getline(cin,name); cout<<"You entered the name: "<<name<<endl; int l=name.length(); cout<<"number of character="<<l<<endl; int c=0; for(int i=0;name[i]!='\0';i++){ c++; } cout<<"length="<<c; return 0; } one more way .
8th Mar 2017, 4:24 PM
Abhishek kumar tantia
Abhishek kumar tantia - avatar
- 1
hello
22nd Mar 2017, 5:33 AM
Abhishek kumar tantia
Abhishek kumar tantia - avatar