we are working with threads, and have to write a program that counts the number of words in an arbitrary number of files, one thread per file. The thread part works fine..the problem is in the little function that counts the words. It is counting the total characters in the files instead of the words.
here it is, any suggestions would be appreciated. I think I have stared at it for too long and might be overlooking something silly.
How about a function that reads and ignores characters until it reaches a whitespace, at which point it increments a counter by one? The counter must start from 1.
Recommendation for this: Use <string.h>.
-Albatross
P.S.-There are more reliable ways to count words, but this is just to get your frontal lobes pointing in the right direction.
Present version of count_words counts number of fragments separated by two not alphanumeric elements. For example, , or . . To calculate words, condition
if (!isalnum(c)&&!isalnum(prevc))
should be modified. Usually, words are separated by a whitespace. So, just modify above condition.
PS. I wonder HOW it calculates number of characters.