I am currently getting the following error
Process terminated with status -1073741819
and I suspect its my fgets() but I have no idea why this is happening, any help would be much appreciated.
//Gets Dictionary from file
char* GetDictionary() {
int ArraySize;
int i = 0;
FILE * DictionaryFile;
//Gets first line (in this case it is the amount of Lines)
DictionaryFile = fopen("dictionary.txt", "r");
fscanf(DictionaryFile,"%d", &ArraySize);
ArraySize = ArraySize + 1;
printf("%d", ArraySize);
fclose(DictionaryFile);
//Gets the array
char* Dictionary = malloc(sizeof(char)*ArraySize);
char Temp[ArraySize];
char TempArray[ArraySize];
DictionaryFile = fopen("dictionary.txt", "r");
while(fgets(Temp, sizeof Temp, DictionaryFile)!=NULL) {
Dictionary[i] = Temp;
//Check The array
printf("%s", Dictionary[i]);
i++;
}
fclose(DictionaryFile);
return Dictionary;
}
Dictionary[i] = Temp;- if that doesn't spew a warning from your compiler, you seriously need to crank up the warning level. That tries to save achar*to achar. Andprintf("%s", Dictionary[i]);isn't any better, sending acharpromoted tointto a format specifier expectingchar*.Dictionary != NULLafter callingfopen. Failure to do so will result in a crash, iffopenwasn't able to open the file.ArraySizerepresent the number of remaining characters or the number of remaining lines of text?