i have written a code for a kind of spellchecker . it reads words frm a input file and computes it hash value and then lookupc in hash table of dictionary of approx 11000 words .but it terminates after certain point in dictionary and gives following access violation error
#include<cstdlib> #include<cstdio> #include<cctype> #include<cstring> void main() { FILE *fp; FILE *fpp; FILE *fpt; char ch; fopen_s(&fp,"dictionary2.txt","r+"); fopen_s(&fpp,"input.txt","r+"); fopen_s(&fpt,"output.txt","w"); int j=0; unsigned hash=0; int i=0; char h[16][16]; char temp[16]; while((ch=fgetc(fp))!=EOF) { while(ch!='\n'){ hash=5*hash + tolower(ch); *(temp+j)=ch;//temp[j]=ch; ch=fgetc(fp); j++; } *(temp+j)='\0'; hash=hash%17; strcpy_s(*(h+hash),temp); hash=0; j=0; for(int i=0;i<16;i++) temp[i]='\0'; } for(j=0;j<16;j++) fprintf(fpt,"\n%d\t%s",j,*(h+j)); while((ch=fgetc(fpp))!=EOF) { while(ch!='\n'&&ch!='\t'&&ch!='.'&&ch!=','&&ch!=' '&&ch!='\0'){ hash=5*hash + tolower(ch); *(temp+j)=ch; ch=fgetc(fpp); j++; } temp[j]='\0'; if(hash!=0){ hash=hash%17; if((strcmp(temp,*(h+hash)))==0){ fprintf(fpt,"\n%s\t%d\tfound",temp,hash); } hash=0; j=0; for(int i=0;i<16;i++) temp[i]='\0'; } } fclose(fp); fclose(fpp); fclose(fpt); }