Ok, I made some code and I get a Windows error when I run the program now. I know it is happening within these functions that load the file.
Code:
int LoadFile(char Name[]){
int Line = 0;
int FileDone = FALSE;
FILE *infile = fopen(Name, "r");
Compiler.Line = Memory(2*sizeof(char*));
while(FileDone==FALSE){
FileDone = GetLine(infile, Line);
CleanString(Compiler.Line[Line]);
printf("%s\n", Compiler.Line[Line]);
Line++;
Compiler.Line = GlobalReAlloc(Compiler.Line, (Line+2)*sizeof(char*), 0);
}
Compiler.TotalLines = Line + 1;
fclose(infile);
return SUCCESS;
}
int static GetLine(FILE *infile, int Line){
int Flag = FALSE;
int Len = MAX_LINE;
char *Temp;
char *Base;
Temp = Memory(Len*sizeof(char));
while(Flag==FALSE){
fgets(Temp, MAX_LINE, infile);
if(Compiler.Line[Line]!=NULL){
Base = Compiler.Line[Line];
}
else{
Base = Memory(MAX_NAME);
strcpy(Base, "");
}
Compiler.Line[Line] = Memory((strlen(Temp)+1+Len)*sizeof(char));
snprintf(Compiler.Line[Line], strlen(Temp)+Len+1, "%s%s", Base, Temp);
GlobalFree(Base);
Base = NULL;
if(Temp[strlen(Temp)-1]=='\n'||Temp[strlen(Temp)-1]=='\0'){
break;
}
Len = Len + MAX_LINE;
GlobalFree(Temp);
Temp = Memory((Len+1)*sizeof(char));
}
GlobalFree(Temp);
if(feof(infile)!=0){
return TRUE;
}
return Flag;
}
I think the error is something happening with the snprintf, but I am not sure. Anyone know what is wrong with this?
- Sean