+ 1

End of line

Can someone please help me understand the below question. what should be the correct approach? I dont want the code. i just want to undertsand the correct motive. want to write the code myself. sir John Wells can you help me with that? Thanks a lot. A line of English text will be given, where words are separated by one of the following symbols: ' ', '\t', '.', ',' and ';' Each word may be separated from the next and the previous by one or more of the following symbols. You have to count the number of words in the sentence. Note that to read the input, you have to read until the EOF symbol is read, as in the following example. int main() { int c; c = getchar(); while ( c != EOF ) { c = getchar(); } return 0; } Note: it is possible to solve this question without arrays, so the maximum length of the line is not important. Input ----- A line of English text with words separated from one another by one or more occurrences of the symbols

19th Sep 2018, 7:32 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
8 Answers
+ 8
Good question 💗🙌
19th Sep 2018, 7:42 PM
NimWing Yuan
NimWing Yuan - avatar
+ 7
Single loop to EOF and one if to increment count can handle it. You just need to know state of current character and remembered state of the last one. If current is not word and last was word, increment. EOF would be treated as not word. On SoloLearn, line feed ('\n') gets automatically added to your input so it must also be not word.
20th Sep 2018, 9:47 AM
John Wells
John Wells - avatar
+ 4
...one,,,,,....two;;;three ... skip as not a word. o found a word. ne skip still a word. , word is done; we now have 1. ,,,,.... skip as not a word. t found a word. wo skip still a word. ; word is done; we now have 2. ;; skip as not a word. t found a word. hree skip still a word. EOF done; we now have 3.
19th Sep 2018, 8:49 PM
John Wells
John Wells - avatar
+ 3
Basically, there are 5 characters that end a word (space, tab, period, comma, or semicolon.) Between two words, you can have any number of those characters. If the character is not one of those 5, it is a member of a word. Find the first word character. Find the first not word character. Count the word. If you were looking for the start of a word and reached EOF, your done counting so display the result. If you were looking for the first not word character and reached EOF, the word is done so count it and your done so display the result.
19th Sep 2018, 8:33 PM
John Wells
John Wells - avatar
+ 2
John Wells for continuing a word, do I have to use do whole loop? and for count no of words should I use loop or if else ?
20th Sep 2018, 6:12 AM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
+ 2
https://code.sololearn.com/c7Uidq55l3Dk/?ref=app John Wells Hello sir, I have written a few lines of my code. I am still not clear about it. can you kindly please help me further in the code. thank you
20th Sep 2018, 12:25 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
+ 1
NimWing Yuan thanx but I am not getting it. can you help?
19th Sep 2018, 8:09 PM
Nilutpol Kashyap
Nilutpol Kashyap - avatar
+ 1
sir I will try to write the code now. once I upload it, kindly please check it. thank you
20th Sep 2018, 9:56 AM
Nilutpol Kashyap
Nilutpol Kashyap - avatar