VAX C help

Mike Farren farren at well.UUCP
Thu Jan 16 17:58:38 AEST 1986

In article <157 at ulowell.UUCP>, rimbold at ulowell.UUCP (Rob Rimbold) writes:
> 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

  << He goes on to describe various problems involved with trying to rewrite
the first integer in the file >> 

    You seem to have a misconception about fprintf, somewhere.  When you
use the format '%d', fprintf will send the ascii representation of the
specified integer to the file, using only as many characters as are
necessary for that integer (i.e., 123 would use 3 characters, 65536 would
use 5).  You can get around this by specifying the field length.  For example,
with 16 bit integers (-32768 to 32767), use the format statement '%6d'.  This
will always allocate 6 characters for the representation, and this can then
be rewritten correctly.

           Mike Farren
           uucp: {your favorite backbone site}!hplabs!well!farren
           Fido: Sci-Fido, Fidonode 125/84, (415)655-0667

More information about the Comp.lang.c mailing list