Basically I'm supposed to make a spell check program and whatever the word is misspelled, it will print out the words from dictionary.txt to match the it (that's where the function will take its role..)
But it keeps crashing whenever I write the first word.
Can anyone help me why my program keeps crashing?
Code:
#include<stdio.h>
#include<string.h>
#define SIZE 40
//Functions that will be used
int substring (char shortstr[], char longstr []);
int subsequence (char shortstr[], char longstr[]);
int permutation (char string1[], char string2[]);
int matchscore (char string1[], char string2[]);
int main () {
//This will read the txt.file
FILE *ifp;
ifp = fopen ("dictionary.txt", "r");
int marker;
char possible_words[3000][30];
char dictionary[30000][30];
char string2[30];
int ans;
char word[30];
int i, max_of_words;
int length1, length2;
//This will read the max of words in the dictionary
fscanf(ifp, "%d", &max_of_words);
//I put the strings ina here to read all of the words from the txt. file.
for (i=0; i<max_of_words ; i++) {
fscanf(ifp, "%s", dictionary[i]);
}
printf("Welcome to the Spell Checker!\n");
printf("The dictionary has been loaded\n\n");
do {
//resets the words for display
//for(i=0; i<30000; i++)
//strcpy(possible_words[i]," ");
printf("Please enter the word you would like checked\n");
scanf("%s", word);
printf("\n");
length1 =strlen(word);
marker=0;
//This will set the loop whether the word matches the dictionary
for (i=0; i<max_of_words ; i++) {
strcpy(string2,dictionary[i]);
length2 = strlen(string2);
if (strcmp(string2, word) == 0){
printf("Great, %s is in the dictionary!\n", word);
marker=1;
}
else if (length1==length2){
if (matchscore(word, string2) ==1 )
strcat(possible_words[i],string2);
else if (permutation(word, string2)==1)
strcat(possible_words[i], string2);
}
else if (length1>length2) {
if (substring(string2, word) ==1 )
strcat(possible_words[i], string2);
else if (subsequence (string2, word) == 1)
strcat(possible_words[i], string2);
}
else if (length1<length2) {
if (substring(word, string2)==1)
strcat(possible_words[i], string2);
else if (subsequence (word, string2) ==1)
strcat(possible_words[i], string2);
}
}
if (marker==0){
for (i=0;i<max_of_words;i++) {
printf("%s", possible_words[i]);
if (strcmp(possible_words[i], "\0") != 0)
printf("\n");
}
}
printf("Would you like to enter another word? (Yes=1/No=0)\n");
scanf("%d", &ans);
} while(ans!=0);
fclose(ifp);
system("PAUSE");
return 0;
}