VAX C help
Ian Seaton, Dedicated Mail, REO2-F/D3, DTN 830 3593
seaton at tron.DEC
Fri Jan 17 19:18:33 AEST 1986
---------------------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 at DECWRL.ARPA
More information about the Comp.lang.c
mailing list