Hey i have a project in which i have to create a spell checker in c. I have a dictionary file named words.txt and i want the user to type in a filename from which the words are going to be compared to the dictionary's (words.txt). Is there a way i can compare the words from the dictionary file itself? i tried copying the whole dictionary in an array but something seems to be wrong with my code. It runs but for some reason it goes into an infinite loop. Could that be caused by the size of the file? if not can someone tell me what is the mistake i have done? the following code is just for copying the two files into two different arrays before comparing them.
Code:
#include<string.h>
#include <stdlib.h>
char dictionary[1000000];
char inputfile[100000];
int main(void)
{
FILE* dict_file;
FILE* input_file;
int bytes_read;
char* p;
char filename[50];
dict_file = fopen("words.txt", "r"); /* Open the dictionary file */
if (dict_file != 0) /* Test if the file is NOT empty */
{
/* Read the dictionary */
p = dictionary;
p = fgets(p, 1000000, dict_file);
while (p != 0)
{
while (*p != '\0')
{
p += 1;
}
p = fgets(p, 1000000, dict_file);
}
}
else
{
printf("\nThe dictionary file is empty. Unable to open file\n");
}
char* pfilename = NULL;
pfilename = (char*)malloc(50);
printf("Please write the name of the input file\n");
scanf("%s", filename);
input_file = fopen(filename, "r");
if (input_file != 0)
{
/* Read the input file */
p = inputfile;
bytes_read = fread(p, 1, 1000, input_file);
p += bytes_read;
while (bytes_read != 0)
{
bytes_read = fread(p, 1, 1000, input_file);
p += bytes_read;
}
*p = 0;
}
else
{
printf("\nThe text file is empty. Unable to open file\n");
}
}