chpicker
Programmer
- Apr 10, 2001
- 1,316
I wrote a function that would read values out of a binary file. It works great for awhile...after reaching a seemingly random point in the file, it just stops working. All subsequent calls will fail until I close the file and reopen it.
Here is my code. "myfile" is a global that is assigned a file handle in a previous function call. _Error is an API call to generate an error message in Visual FoxPro:
[tt]
double getdouble(void)
{
if (myfile==NULL) // No file is open
{
_Error(113);
return (double)0;
}
double i;
if (fread(&i,sizeof(double),1,myfile)>0)
// read successful
return i;
else // Error reading file
_Error(104);
return (double)0;
}
[/tt]
After calling this routine a few times and working my way into the file, the fread() simply stops getting data. It happens in the exact same place in a given file, but different places in different files. I'm pretty sure I haven't gone past the EOF since the data that has been retrieved up to this point is still near the beginning.
Any ideas what could cause this?
Ian
Here is my code. "myfile" is a global that is assigned a file handle in a previous function call. _Error is an API call to generate an error message in Visual FoxPro:
[tt]
double getdouble(void)
{
if (myfile==NULL) // No file is open
{
_Error(113);
return (double)0;
}
double i;
if (fread(&i,sizeof(double),1,myfile)>0)
// read successful
return i;
else // Error reading file
_Error(104);
return (double)0;
}
[/tt]
After calling this routine a few times and working my way into the file, the fread() simply stops getting data. It happens in the exact same place in a given file, but different places in different files. I'm pretty sure I haven't gone past the EOF since the data that has been retrieved up to this point is still near the beginning.
Any ideas what could cause this?
Ian