|
-
August 22nd, 2004, 03:25 PM
#1
Problems with fseek, not notifying past end of file
I'm using 'fseek' and when I try to set the pointer beyond the end of file, I don't get and error message. Does anybody know how to generate an error message from from 'fseek' to monitor when you have gone beyond the end of file.
Here is my code:
struct Person
{
int RecNum;
char Type[11];
char CoName[41];
char LastName[41];
char FirstName[41];
char Address[61];
char TeleNum[16];
};
struct Person DB;
void rfile_db(void) // READ A RECORD TO DB
{
FILE *fptr;
int bytes_out;
CString msg;
if ((fptr = fopen("temp3.rec", "r+b")) ==NULL)
{
AfxMessageBox("Can't Open/Create File ");
}
// recno is the max # of records in the file
offset = recno * sizeof(DB); // DB is a struct of the file
msg.Format( "Recno = %d", recno);
AfxMessageBox(msg);
if (fseek(fptr,offset,SEEK_SET) !=0){
AfxMessageBox(" can't move pointer there");
}else{
bytes_out = fread(&DB, sizeof(DB),1, fptr);
fclose(fptr);
if (bytes_out) AfxMessageBox("File was Read, Bytes = ");
}
fclose(fptr);
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|