File Opening Throws a Illegal Op.
Hello,
I haven't programmed in a while and I am trying to make a simple flashcard type program to drill myself on a foreign language.
However for the open file function, to open the flashcard text files, it keeps throwing an Illegal Op. message in Kernel32.dll. Here is the function, which I know is where the problem is at least occuring, if not the only place with trouble.
Specifically I have narrowed the fault down to the last fseek() function, if that helps.
Code:
void OpenCards(HWND hwnd, char *filename)
{
FILE *file = NULL;
fpos_t length = 0;
char *buff = NULL;
file = fopen(filename,"rt");
if(!file)
{
MessageBox(hwnd,"Couldn't load file!","Error",MB_OK | MB_ICONERROR);
return;
}
fseek(file,0,SEEK_END);
fgetpos(file,&length);
buff = new char[(int)length + 1];
if(!buff)
{
MessageBox(hwnd,"Couldn't load OurFile.txt","Error",MB_OK | MB_ICONERROR);
return;
}
fseek(file,0,SEEK_SET); //this is where the fault is
fread(buff,(int)length,1,file);
buff[(int)length] = NULL;
fclose(file);
ProcessCards(hwnd, buff);
}