Path: utzoo!utgpu!watserv1!watmath!att!dptg!ulysses!andante!mit-eddie!bloom-beacon!eru!hagbard!sunic!news.funet.fi!tukki.jyu.fi!jyu.fi!otto From: otto@tukki.jyu.fi (Otto J. Makela) Newsgroups: comp.lang.c Subject: Re: Turbo C, fopen(), fprintf() and ^Z - I need help!! Message-ID: Date: 20 Sep 90 16:04:45 GMT References: <38742@ucbvax.BERKELEY.EDU> <14084@mentor.cc.purdue.edu> <1990Sep20.014132.29461@druid.uucp> Sender: news@tukki.jyu.fi (News articles) Organization: Turing Police, Criminal AI section Lines: 24 In-Reply-To: darcy@druid.uucp's message of 20 Sep 90 01:41:32 GMT In article <1990Sep20.014132.29461@druid.uucp> darcy@druid.uucp (D'Arcy J.M. Cain) writes: [how to position file to skip trailing ^Z's on brain-dead CP/M -like systems] long pos = 0; ... do { fseek(fp, --pos, SEEK_END) } while ((c = fgetc(fp)) == 0x1a); fseek(fp, ++pos, SEEK_END); Be careful with this stuff. Because you reseek as the last thing you do, this will work. I have seen several C librarys which get confused when you seek, read and then write a stream (probably some buffering messing things up). Or is this perhaps (horror of horrors) standard behaviour ? I wrote code like: fseek(fp, -1L, SEEK_END); while(fgetc(fp)==0x1A) fseek(fp, -2L, SEEK_CUR); At this point I assumed the file would be positioned correctly. Didn't work on DOS, didn't work on BSD Unix. I had to add: fseek(fp, 0L, SEEK_CUR); But you of course were aware of this. -- * * * Otto J. Makela * * * * * * * * * * * * * * * * * * * * * * Phone: +358 41 613 847, BBS: +358 41 211 562 (CCITT, Bell 2400/1200/300) * * Mail: Kauppakatu 1 B 18, SF-40100 Jyvaskyla, Finland, EUROPE * * * * Computers Rule 01001111 01001011 * * * * * * * * * * * * * * * * * * *