Turbo C, fopen(), fprintf() and ^Z - I need help!!

D'Arcy J.M. Cain darcy at druid.uucp
Thu Sep 20 11:41:32 AEST 1990


In article <14084 at mentor.cc.purdue.edu> edgincd2 at mentor.cc.purdue.edu (Chris Edgington *Computer Science Major*) writes:
>In article <38742 at ucbvax.BERKELEY.EDU>, brand at janus.Berkeley.EDU (Graham Brand) writes:
>> instruction. The problem that I am having is that the line that is 
>> appended in the file is preceeded with a ^Z which makes the data
>> invisible when a type command is issued from MSDOS. I can use vi and
>
>Is the ^Z leftover from the original dos file or is it the first character of
>the append data??  If it is leftover from the original file, you could you
>fsetpos to set the position for writing as eof(original)-1, then it would
>erase the ^Z
>
But don't open the file in append mode.  It repositions the file pointer to
the end of the file before each write.  Also you might want to check to see
if the last character is a ^Z as well as the ones before the last.  Some of
those old programs use the CP/M method of filling a buffer with ^Zs before
writing to it so you could have as many as 128 of them.  This might work:

    long pos = 0;
    ...
    do { fseek(fp, --pos, SEEK_END) } while ((c = fgetc(fp)) == 0x1a);
    fseek(fp, ++pos, SEEK_END);

That leaves the file pointing to the first of any ^Zs or the end of file
if there are none.


-- 
D'Arcy J.M. Cain (darcy at druid)     |
D'Arcy Cain Consulting             |   MS-DOS:  The Andrew Dice Clay
West Hill, Ontario, Canada         |   of operating systems.
+ 416 281 6094                     |



More information about the Comp.lang.c mailing list