Count words in a document
Hello all,
I want to count words in a document. First I have made a program that count letters in a document:
#import <foundation/foundation.h>
int main(int argc, const char * argv[])
{
int count={0},n={0},SearchChar;
FILE *document;
document=fopen("/Users/mymac/Desktop/test.txt","r");
SearchChar='H';
while(n!=EOF)
{
if ((n=fgetc(document))==SearchChar) {
count+=1;
}
}
printf("%d\n",count);
fclose(document);
return 0;
}
I have no idea how to count words in a document (as you can see it is a .txt document). Which command do I need fgetc can't handle words, but is there a command that can handle words.
RL6001