Mail Archives: djgpp/2012/05/05/10:45:37

X-Authentication-Warning: mail set sender to djgpp-bounces using -f
From: Georg <dosusb AT googlemail DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: freopen
Date: Sat, 5 May 2012 07:27:54 -0700 (PDT)
Lines: 28
Message-ID: <>
References: <4182049f-12cf-4935-892b-daeaac0f3fd8 AT v2g2000vbx DOT googlegroups DOT com>
<a0j2npFlg6U1 AT mid DOT dfncis DOT de> <3394f14f-8b8e-4b81-baa2-1f986b13d4eb AT p21g2000vby DOT googlegroups DOT com>
<a0kkcvF69jU1 AT mid DOT dfncis DOT de>
Mime-Version: 1.0
X-Trace: 1336228074 19101 (5 May 2012 14:27:54 GMT)
X-Complaints-To: groups-abuse AT google DOT com
NNTP-Posting-Date: Sat, 5 May 2012 14:27:54 +0000 (UTC)
Complaints-To: groups-abuse AT google DOT com
Injection-Info:; posting-host=; posting-account=v5xbdQoAAAAOGc9Ccc-kLZyobvPlN3Qr
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:
Gecko/20091016 Firefox/3.5.4,gzip(gfe)
Bytes: 2409
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
X-MIME-Autoconverted: from quoted-printable to 8bit by id q45Ej291030047
Reply-To: djgpp AT delorie DOT com

On May 5, 2:22 pm, Hans-Bernhard Bröker <HBBroe DOT  DOT  DOT  AT t-online DOT de> wrote:
> On 05.05.2012 08:01, Georg wrote:
> > "FILE *freopen(const char *filename, const char *mode, FILE *file);
> > Description
> > This function closes file if it was open, then opens a new file like
> > fopen(filename, mode) (see section fopen) but it reuses file."
> > I read this description that the third parameter of freopen is closed,
> > in my example it is stdout. The resulting handle is associated with
> > stdout.dat and I do not see that this gets closed.
> I think you overlooked that in your example, you called freopen()
> _twice_.  The first time you replaced the stdout handle by the file
> "stdout.dat", the second time you closed that and replaced stdout by a
> handle to the console.
> When your example fclosed() the FILE *f returned by the first freopen(),
> you actually closed stdout itself.

I guess I still do not understand it completely but when I remove
fclose(f); it works. And since you said the second freopen() closes
"stdout.dat" I do not need to explicitly close that.

Thank you. Georg

- Raw text -

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