I have a piece of code that counts the number of words input by the user using strtok. However, I am struggling with converting this program to do the same thing but instead of the user inputting the text, it will read from a text file, counting the number of words in the text file.
Ne tips would be greatly appreciated.
#define MAX_LINE 80
char delim = " ,.!;:\n"; /* sets up word separators*/
char *words, *ptr;
int count = 0;
printf("Enter line of text \n");
while ((words = strtok(ptr, delim)) !=NULL)
ptr = NULL;
printf("there were %d words in the string \n",count);