I'm scanning a file to see if user input matches a word in the txt file.. if it matches.. increase the array size and add the word. This is a 2d array. "max_word_size" is currently just a constant variable.
void UserMode(char userAnswers[][max_word_size], int *size)
{
FILE *fid = fopen("dict.txt","r");
char dictWord[max_word_size], userWord[max_word_size];
bool found;
int i;
{
printf("Enter a word to check: ");
scanf("%s", userWord);
for (i=0; i<strlen(userWord); ++i)
userWord[i] = tolower(userWord[i]);
found = false;
while (!feof(fid) && userWord != dictWord)
{
fscanf(fid, "%s", dictWord);
if (strcmp(dictWord, userWord) == 0)
{
printf("Found the word in dictionary! Saving answer.\n");
found = true;
strcpy(userAnswers[*size - 1],userWord);
++(*size);
system("pause");
realloc(userAnswers, sizeof(char) * int(max_word_size));
}
}
if (!found)
printf("Could not find word in dictionary! Not saving answer.\n");
}
}