append mode "a" query

chet at uwovax.uwo.ca chet at uwovax.uwo.ca
Fri Feb 16 06:32:47 AEST 1990


Thanks for the help with my append mode query. With your help and some
luck, I've figured out part of what happened, but there is still a
little mystery involved which makes it worth this final posting.

(1) first, the problem is just an MS-DOS problem; both the Sun and the
VAX C compilers run B without problem

(2) The EOF (^Z, dec 26) was introduced by an assembly language editor
that I sometimes use. When I used only MicroEMACS, program B ran
without problem on Turbo C and Small-C. Whenever I used the other
editor, the ^Z crept in (I used a third, binary, editor to confirm
these facts).

(3) For Turbo C, a simple fix was to change the mode from "a" (which by
default is "at") to "r+" and then use lseek(fp, -1, 2). This position
the file pointer just before the EOF. Note, however, that it should not
be necessary to do this!

(4) Small-C (version 2.2 on MS-DOS) does not have an fseek() function,
and I have so far been unsuccessful in my attempts to use the
substitute function, bseek(), to achieve what I did in Turbo C with
lseek().

(5) I don't know what the Turbo C compiler does, but Jim Hendrix
describes the operation of fopen() very clearly in his book on Small C,
and according to his description, the DOS EOF sign (^Z) should be
changed to -1 on opening (presumably Turbo C does the same thing), and
it should not be possible to append text after it. This is the bit of
mystery that remains.

Chet Creider
creider at csd.uwo.ca



More information about the Comp.lang.c mailing list