How would that work if it was coming from a file? Isn't scanf for user input?Do you think I could use getc() to do it? also what kind of conditions should I have to count it correctly since there can be multiple spaces/whitespace?
You don't need to worry about lines (see description of scanf() %s which I quoted earlier). All you do need to worry about is that the string variable which you read your words into is big enough to hold the longest word that you are going to read (suggest using something like 1000 char).
And you must test the return value of the fscanf() to check whether it actually has read a word or not - if it hasn't then you can assume you've reached the end of the file.
Hanna Roberts wrote:For example the file could look like this:
For future reference...examples are great, however you should really try and write a spec. You want to write out the exact rules that take into account every possible scenario. That's what Piet wrote in his post after yours...it is unambiguous as to what counts as a word and what doesn't (at least, I can't think of a case it doesn't account for). With your example, it certainly helped, but wasn't definitive.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Yeah I get that, it was mainly because the instructions I was given for the assignment were pretty vague so when I wrote the example I wasn't exactly sure if symbols and things were to be counted as words. I'll try to be more specific in the future though, thanks