Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.3 4.3bsd-beta 6/6/85; site decwrl.DEC.COM Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!decwrl!dec-rhea!dec-tron!seaton From: seaton@tron.DEC (Ian Seaton, Dedicated Mail, REO2-F/D3, DTN 830 3593) Newsgroups: net.lang.c Subject: Re: VAX C help Message-ID: <511@decwrl.DEC.COM> Date: Fri, 17-Jan-86 04:18:33 EST Article-I.D.: decwrl.511 Posted: Fri Jan 17 04:18:33 1986 Date-Received: Sat, 18-Jan-86 08:32:26 EST Sender: daemon@decwrl.DEC.COM Organization: Digital Equipment Corporation Lines: 73 ---------------------Reply to mail dated 14-JAN-1986 01:42--------------------- In his recent posting Rob Rimbold asks: >While writing a program that does a lot of file I/O, I have come >across a few problems. I am writing integers to a file as integers using >"%d" and fprintf. I open the file using "r+". I would like to keep track >increment or simply change the integer that is already recorded in the file. >My problem is that when rewinding to the beginning of the file and >re-writing another integer the following things occur: >1. If the integer previously in the file is a single digit, only a single > digit may be written over it, the same thing goes for double or > triple digit integers. That is correct, if you open the file "r+" you can read/modify the data there, NOT extend it (ie 1 digit -> 3 digits). The "workaround" is to write formatted data: fprintf( file_desc, "%03d", number ); or replace 3 with the maximum length of the number string. Reading is just as easy: fscanf( file_desc, "%d", &number ); >2. If I attempt to 'reopen' the file and write into it with "w" or "w+" > access, and use the same file (i.e. same version all the time.), > it won't let me. Same goes for the close-and-open ploy. This is VAX/VMS you're talking to what did you expect? "w" opens a file for writing and creates a new file. If the file already exists, it creates a new file with the same name and a higher version number. "w+" opens a new file for write update access >3. If I close the file, and reopen it with "r+", I still am unable to > modify it past the number of digits that already exist there. > I don't get errors for any of this, simply nothing happens. See 1. above. >Also, how does one go about deleting a file using VAX C? I was unable >to figure it out. It seems that almost every function is listed as >'not provided' in the back of the manual. I am getting desperate. Desperate enough to READ the manual? int delete( file_spec ) char *file_spec; Returns 0 if successful, -1 if it fails. >It seems that workarounds are ever so necessary when using this cruddy >compiler. ANY ideas or suggestions would be most appreciated. Of course, >snippets of code for examples are EVEN more welcome. RTFM Rob... Share and Enjoy... Ian Seaton DEC Reading, England UUCP: !dec-thrint! decwrl!dec-rhea!dec-tron !seaton !dec-blott ! ARPA: seaton%tron.DEC@DECWRL.ARPA