I'm trying to scan a list of words into an array based on some input from a text file. The first number indicates the amount of words in the text file. The longest word will be 29 characters (I'm still not sure how to do this). The dictWord is to store the words, but I don't know how to set the number in the array to the first number in the text file, and set the maximum length of the word to 29 characters.
When I run this and attempt to print out the fourth word in the array to test if it's working, the program prints out this:
רת"
instead of words. Can anyone give advice as to why?
Code:
#include <stdio.h>
int main(void)
{
FILE* fin;
fin=fopen("textmsg.txt", "r");
int i;
int numWords;
fscanf(fin, "%d", &numWords);
char dictWord[numWords][29];
for(i = 0; i < numWords; i++)
{
fscanf(fin, "%s", dictWord[i]);
}
printf("%s", dictWord[4]);
system("PAUSE");
return 0;
}
The format of the textmsg.txt file is as follows:
4
these
are
four
words