www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/12/13/09:09:10

Xref: news-dnh.mv.net comp.os.msdos.djgpp:3811
Newsgroups: comp.os.msdos.djgpp
Path: news-dnh.mv.net!mv!news.sprintlink.net!newsfeed.internetmci.com!howland.reston.ans.net!news.nic.surfnet.nl!rug.nl!csg676
From: csg676 AT cs DOT rug DOT nl (Berend Reitsma)
Subject: Re: Strange bug using 'fwrite'
Sender: root AT rug DOT nl (Operator)
Nntp-Posting-Host: rug100.cs.rug.nl
Organization: Dept. of Computing Science, Groningen University
References: <4agbj6$1vm AT bmerhc5e DOT bnr DOT ca>
Distribution: na
Date: Tue, 12 Dec 1995 12:26:56 GMT
Lines: 35
To: djgpp AT sun DOT soe DOT clarkson DOT edu
Dj-Gateway: from newsgroup comp.os.msdos.djgpp

In article <4agbj6$1vm AT bmerhc5e DOT bnr DOT ca>, cbutler AT bnr DOT ca (Chris Butler) writes:
> Hi folks,
> 
>    I was coding away this weekend when the following bug
> stopped me dead.
> 

>    f2 = fopen("out.2", "w");

Opens in textmode, I gues. This means under DOS conversion of
'\n' to '\r' '\n'.
You need to open in binary mode "wb".

> 61 62 63 64 01 00 00 00  02 00 03 00 05 06 07 08
> 09 0d 0a 0b 0c 0d 0e 0f  10 11 12 13 14 15 16 17
> 18

> ...for a grand total of 33 bytes, where I was only expecting 32.
> Note also the '0d', second byte on the 2nd line.  Anyone have
> any ideas where it came from?  The program works as I'd expect
> it to on UNIX.  I haven't tried rewriting the above to use
> file descriptors instead of file pointers, so I'm not sure
> what happens there.
> 
>    Also, I messed around with the initialization of the 'extra_bytes'
> in other tests - the '0d' always seems to follow the '09'.

No, 0d is inserted before 0a e.g. '\r'...

> Chris Butler aka cbutler AT bnr DOT ca -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>          All standard disclaimers apply.  Have an adequate day.

--
Berend Reitsma,   cgs676 AT cs DOT rug DOT nl
                         wing.rug.nl

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019