C code to count the number of words in a string