Counting the number of words in a string

Here’s my code : http://ideone.com/MuJdnB

t is the number of test cases. I am just counting the number of spaces in the string and printing the final answer as number of spaces + 1 . The problem is that it’s taking only 3 inputs instead of 4. It outputs 1 for the first test case without getting a string. Please help me find the error in my code. Thanks.

this is the corrected code…LINK…the extra getchar() is to flush the ‘\n’ in the buffer…hope this helps…:slight_smile:

1 Like
//