I'm very new to programming and I'm trying to load a dictionary from a text file to a linked list. I use a while loop for this but my code reads the last word twice (I also ran gdb to verify it). I guess something if my while condition is not working well but I cannot figure out why? Anyone can help me understand this?
Here is my code char* text = "small.txt";
// open the dictionary file
FILE* fp = fopen(text, "r");
if (fp == NULL)
{
printf("Could not open %s.\n", text);
// unload();
return 1;
}
// temporary storage for current word
char curr_word [LENGTH + 1];
node * curr, * head;
head = NULL;
while (feof (fp) == 0)
{
curr = malloc(sizeof(node));
fscanf (fp, "%s", curr_word);
strcpy (curr -> word, curr_word);
curr -> next = head;
head = curr;
}