Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!julius.cs.uiuc.edu!ux1.cso.uiuc.edu!osiris.cso.uiuc.edu!gordon From: gordon@osiris.cso.uiuc.edu (John Gordon) Newsgroups: comp.lang.c Subject: Re: Random Access files Message-ID: <1990Nov20.014554.17886@ux1.cso.uiuc.edu> Date: 20 Nov 90 01:45:54 GMT References: <90322.032603TRM900@psuvm.psu.edu> Sender: news@ux1.cso.uiuc.edu (News) Organization: University of Illinois at Urbana Lines: 24 Tony R. Marasco writes: >Hello. I am trying to use random access files and have run into some >problems... >I am using _fopen_ with a "w+b" parameter to create the file (if it doesn't >exist). If it exists, I use "r+b". Otherwise it seems to erase the file >like PASCAL's _rewrite_. How am I doing so far?? Opening a file in "w" mode is supposed to destroy existing files. If you don't want to do this, open in "a" mode. >I am also using _fseek_ to position the file pointer (recnum*size of struct) >with SEEK_SET. I do this before each _fread_ & _fwrite_. The program >seems to "lose" a few bytes at the beginning of each _fread_. The first record number should be at recnum 0. Are you starting at recnum 1? >What is more astounding is I can write a record that doesn't exist, but >I can't update a record that already exists. I think that opening in "a" might work.