0
Can anyone please help me How to find string length with whitespaces?
9 Answers
+ 4
Nandini B N just have a look at this code and input "hello world" đ
https://code.sololearn.com/czLg77udBF93/?ref=app
+ 3
Language ?
+ 2
In what programming language?
+ 1
Use fgets() or getline() function to take a larger input including white spaces. and them process it like usual string.
+ 1
Thank you for your answers đ
0
C++
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
0
I tried str.length() but it doesn't count spaces in string
0
I'm asking the answer for taking the input from the user