Hey all,
I've been making a program that reads in from a .txt file which is a dictionary of one word on each line like so;
aa
aah
aahed
aahing
aahs
aal
aalii
aaliis
aals
What I want to do is read in from the text file and store each string from each line into an array and be able to call that string later on. For example with the above text calling words[1] would return "aah". Here is my code that I have so far below, at first it seems to work but it looks like it fills all of the array with the last word in the text file? Any help would be greatly appreciated!
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
int dicsize = 80368;
char newword[100];
char* words[dicsize-1];
// Load Files
FILE *dict;
dict=fopen("dictionary.txt", "r");
if (dict==NULL) {
printf("Unable to open dictionary.txt\n");
} else {
// Input Dictionary
int i = 0;
while (fgets(newword, sizeof newword, dict) != NULL) {
printf("%s", newword);
words[i] = newword;
i++;
}
}
printf("\nTest: %s", words[2]);
return(0);
}