0

Can anyone please help me How to find string length with whitespaces?

20th Jul 2020, 3:20 PM
Nandini B N
9 Answers
+ 4
Nandini B N just have a look at this code and input "hello world" 👇 https://code.sololearn.com/czLg77udBF93/?ref=app
20th Jul 2020, 3:38 PM
Arsenic
Arsenic - avatar
+ 3
Language ?
20th Jul 2020, 3:27 PM
Arsenic
Arsenic - avatar
+ 2
In what programming language?
20th Jul 2020, 3:27 PM
Lakshay Mittal
Lakshay Mittal - avatar
+ 1
Use fgets() or getline() function to take a larger input including white spaces. and them process it like usual string.
20th Jul 2020, 3:28 PM
Arsenic
Arsenic - avatar
+ 1
Thank you for your answers 😊
20th Jul 2020, 3:43 PM
Nandini B N
0
C++
20th Jul 2020, 3:28 PM
Nandini B N
0
#include<iostream> #include<cmath> #include<string> using namespace std; int count=0,i,len; double avg; string str; int main() { int T; cin>>T; while(T--) { getline(cin,str); len=str.size(); cout<<len; for(i=0;i<len;i++) { int s=str[i]; if(isspace(s)) { count+=1; } } int a=len-count; avg=a/count; cout<<floor(avg)<<endl; } return 0; } What is wrong in this code
20th Jul 2020, 3:32 PM
Nandini B N
0
I tried str.length() but it doesn't count spaces in string
20th Jul 2020, 3:35 PM
Nandini B N
0
I'm asking the answer for taking the input from the user
20th Jul 2020, 3:37 PM
Nandini B N