I am working now on pset5, trying to degrade each task into pieces. So now, I have written some code that just reads words from a file I have created, it then prints each word it read. The problem is that the program prints the last word twice. I don't know why.
Here is the code
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#define LENGTH 45
int main() {
char * word = malloc(sizeof(char)*LENGTH);
FILE * fp = fopen("source.txt","r");
if (fp ==NULL) {
printf("File not found!\n");
return 1;
}
do {
fscanf(fp,"%s",word);
*word = tolower(*word);
printf("%s \n",word);
}
while(!feof(fp));
free(word);
fclose(fp);
}