How to print the count of no of articles in the string?

My program works fine when there is no comma or fullstop. Input I am a, active person in an, world the. output 3 my output 0 How can I print 3 https://code.sololearn.com/c989sOo7mmBo/?ref=app


8/23/2019 1:33:37 PM


4 Answers

New Answer


your program splits the input in words by spaces, so b will have the value of "a," instead of "a" and so on


Thats because the comma, fullstop, semicolon, etc. are directly connected to the article. In normal phases the " " will seperate them. So just have to delete the symbols 😊 Or replace all your if statements like this: strstr(b, "the") != NULL


Your code barely works for the given string and would need to be completely rewritten for a different string. That's a bad software design, a brute force technique. That's OK your learning and you have tried something but it didn't work. Take a look at the strtok() function in the standard libraries. It is specifically designed to tokenise strings separated by specific delimiters... http://www.cplusplus.com/reference/cstring/strtok/


I got 2. That is strange. Wonder how. 🤔