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?
13 Respostas
+ 1
@1AmNotok but it doesn't work
+ 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
+ 1
@Martin Thanks a lot for the information. I have learned a lot from you.
+ 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.
+ 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?
+ 1
Thank you @Martin..Now I got it. And yes actually I included the header file cstring in codeblocks but not here.
0
I think your current program is able to read multiple lines of text under the limit(80 char)