Im trying to create a spellchecker, iv created a reference file containing a list of words. I need to be able to check text files against this and if the words are incorrect i want to b able to print these to a new file including the line it appears on and any words it actually could b. This is wot iv got so far, its not much coz im getting really confused:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
char** allocate(int str_length)
{
char** word_store;
word_store = (char**)(malloc(str_length*sizeof(char*)));
return word_store;
}
void de_allocate(char** word_store, int str_length)
{
int i;
for (i=0; i<=str_length; i++)
free(word_store[i]);
free(word_store);
}
int main(void)
{
char buffer[100];
char** word_store;
int space=0, words=0;
FILE* in_file;
if((in_file=fopen("textfile.txt","r"))==NULL) /*opening the file as named*/
printf("File open failed\n");
while(1)
{
if(fgets(buffer,100,in_file)==NULL) break; /*scanning the file using buffer as temp store,
max of 100 characters per line*/
while(1)
{
if(isspace(buffer)) /*if buffer is a space, increment 'space' which*/
space++; /*will then give a number of words in the file*/
printf("%d ",space);
if(buffer == EOF) break; /*this is where i got really confused*/
/*think i need to call on the allocate function here, then move on to scan
in the seperate words and store them into word_store*/
}
/*{
sscanf(buffer, "%s", word_store[]);
words++;
}*/
}
fclose(in_file);
return 0;
}