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 well.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!seismo!lll-crg!well!farren From: farren@well.UUCP (Mike Farren) Newsgroups: net.lang.c Subject: Re: VAX C help Message-ID: <493@well.UUCP> Date: Thu, 16-Jan-86 02:58:38 EST Article-I.D.: well.493 Posted: Thu Jan 16 02:58:38 1986 Date-Received: Fri, 17-Jan-86 06:37:32 EST References: <157@ulowell.UUCP> Distribution: net Organization: Whole Earth Lectronic Link, Sausalito, CA Lines: 21 In article <157@ulowell.UUCP>, rimbold@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