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

Otto J. Makela otto at tukki.jyu.fi
Fri Sep 21 02:04:45 AEST 1990


In article <1990Sep20.014132.29461 at druid.uucp> darcy at 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 <otto at jyu.fi> * * * * * * * * * * * * * * * * * * * * *
* 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 * * * * * * * * * * * * * * * * * * *



More information about the Comp.lang.c mailing list