End of line | SoloLearn: Learn to code for FREE!


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

9/19/2018 7:32:52 PM

Nilutpol Kashyap

8 Answers

New Answer


Good question 💗🙌


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.


...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.


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.


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 ?


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


NimWing Yuan thanx but I am not getting it. can you help?


sir I will try to write the code now. once I upload it, kindly please check it. thank you