Good afternoon. I am writing a program that needs to open a text file, read the number of words in said file. and then, using a loop, load those words into elements of an array. The dictionary file won't have anymore than 10,000 words.
My program compiles without issue, but when it runs, it prints the number of entries in my test dictionary to test that the number is being ready properly by my program, and then has a windows error at the next fscanf when I am attempting to read each word into an array element.
Thanks for your time.
Code:
#include <stdio.h>
#include <string.h>
int main(void) {
int i, wordCount;
char wordBank[9999];
FILE * ifp = fopen("dictionary.txt", "r"); //open dict file
fscanf (ifp, "%d ", &wordCount); //read number of words in dictionary
printf ("%d\n", wordCount); //verified number is being read
for (i = 0; i < wordCount; i++) //load wordbank array with words
{
fscanf (ifp, "%s", wordBank[i]);
printf ("%s \n", wordBank[i]);
}
fclose; //close dict file
}