0

Counting the number of words using string

https://code.sololearn.com/ca11a6A7A227 this code can read only one line of text and printing the number of words present in that text. But if I want my code to read multiple lines of text and printing the number of words altogether, what kind of a change I might need to bring to the code?

29th Apr 2021, 4:49 PM
Ramisa Fariha
Ramisa Fariha - avatar
13 Respostas
+ 1
@1AmNotok but it doesn't work
29th Apr 2021, 6:51 PM
Ramisa Fariha
Ramisa Fariha - avatar
+ 1
Martin Taylor I didn't think it as an array of string objects, i tried to say that the program could read mutiple lines containing less than 80 characters. But there is a chance of buffer overflow. By the way, it is better to use string class of C++ and take string input by getline() function
30th Apr 2021, 4:01 AM
1AmN0t0k@eArth
+ 1
@Martin Thanks a lot for the information. I have learned a lot from you.
30th Apr 2021, 6:52 AM
Ramisa Fariha
Ramisa Fariha - avatar
+ 1
Martin Taylor Oh. I didn't notice that input function clearly . I was actually talking about char array and what appeared to me after running the program.
30th Apr 2021, 8:33 AM
1AmN0t0k@eArth
+ 1
@Martin https://code.sololearn.com/c81a2A5A24a3 I have tried the code where the number of words will be counted reading the multiple lines. "My name is Ramisa Fariha.I love to watch movies and series. My Favourite movie is walk to remember and favourite series is FRIENDS." If I give this as input, the number of words results in 22 instead of 24.Is it Because is and FRIENDS go to the new line and that is why they are not counted or something not given about it in the code?
1st May 2021, 8:13 AM
Ramisa Fariha
Ramisa Fariha - avatar
+ 1
Thank you @Martin..Now I got it. And yes actually I included the header file cstring in codeblocks but not here.
1st May 2021, 12:17 PM
Ramisa Fariha
Ramisa Fariha - avatar
0
I think your current program is able to read multiple lines of text under the limit(80 char)
29th Apr 2021, 5:56 PM
1AmN0t0k@eArth