hello everyone. I'm a beginner to C programming. I'm trying to learning how to code a spell checker that looks through all the words in a dictionary file, compare them with an article, print out all the words that do not exist in the dictionary file onto the console. Since I'm studying malloc in class, I've lowercased every word, removed all the punctuations in the article, and string copied them into malloc. I don't know what should the next step be, would someone give me a hint? Thanks
MAIN.C
#include <stdio.h>
#include <stdlib.h>
char dictionary[1000000];
char article[100000];
void spellCheck(char[], char[]);
int main(void) {
FILE* dict_file;
FILE* article_file;
int bytes_read;
char* p;
dict_file = fopen("american-english.txt", "r");
if (dict_file == 0) {
printf("unable to open dictionary file \"american-english.txt\"\n");
return -1;
}
article_file = fopen("article.txt", "r");
if (article_file == 0) {
printf("unable to open file \"article.txt\"\n");
return -1;
}
/* read dictionary */
p = dictionary;
p = fgets(p, 100, dict_file);
while (p != 0) {
while (*p != '\0') {
p += 1;
}
p = fgets(p, 100, dict_file);
}
/* read article */
p = article;
bytes_read = fread(p, 1, 1000, article_file);
p += bytes_read;
while (bytes_read != 0) {
bytes_read = fread(p, 1, 1000, article_file);
p += bytes_read;
}
*p = 0;
spellCheck(article, dictionary);
}
PROJECT.C
void spellCheck(char article[], char dictionary[]) {
int len = strlen(article) + 1;
int i;
char* tempArticle;
tempArticle = malloc(len);
if (tempArticle == NULL) {
printf("spellcheck: Memory allocation failed.\n");
return;
}
for(i = 0; i < len; i++)
tempArticle[i] = tolower(article[i]);
i=0;
while (article[i] != '\0'){
if (article[i] >= 33 && article[i] <= 64)
article[i] = ' ';
}
printf("%s", tempArticle);
free(tempArticle);
}