Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Having problems with fwrite

Status
Not open for further replies.

Flappy

Programmer
Jul 30, 2002
35
AU
Hi, I havent had much experience with doing random access with fwrite so I'm getting this problem with it. When I write some information to a specific point within the file, it seems to end the file straight after the data I've just written and I lose the rest of the file??..

Heres the code..

Code:
static bool writeRow(struct Table* table, int pos, void* buffer, int size) {
    long location;
    FILE *fp;

    location = table->header->headerSize + (pos * table->header->rowSize);

    if ((fp = fopen(table->path, "wb+")) != NULL) {
      fseek(fp, location, SEEK_SET);
      fwrite(buffer, size, 1, fp);
      fclose(fp);
    } else
      return false;
}
 
You want "a", not "w" in the open mode

You also need a
return true;

--
 
Cool thanks Salem, I realised I forgot to write return true the moment after I hit the submit post button [morning]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top