When I write my program. I can get total number of words+1. So in order to get the correct number, I have to subtract 1 from the output. So can any one suggest the improvement for my code.
Your input data has a newline (as it should) after the last word. Whitespace at the end. Not at EOF yet. Therefore, you do (try) to read one more word and increment the counter. You don't test whether your read operation actually succeeds.
My version attempts to read a word, tests for possible failure, and thus breaks out of the loop without bogus count.