X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: =?ISO-8859-1?Q?Hans-Bernhard_Br=F6ker?= Newsgroups: comp.os.msdos.djgpp Subject: Re: freopen Date: Sat, 05 May 2012 14:22:59 +0200 Lines: 19 Message-ID: References: <4182049f-12cf-4935-892b-daeaac0f3fd8 AT v2g2000vbx DOT googlegroups DOT com> <3394f14f-8b8e-4b81-baa2-1f986b13d4eb AT p21g2000vby DOT googlegroups DOT com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.dfncis.de t+iGDblCCr+H50Pi17zwBg/WrgTEjTe5cjB9xhJSJYtXdDIIgCYoErGjIK6c1sTOPX3qa8GWPX Cancel-Lock: sha1:YByIwSj3sZp+7w627GEbyFCBpL8= User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120420 Thunderbird/12.0 In-Reply-To: <3394f14f-8b8e-4b81-baa2-1f986b13d4eb@p21g2000vby.googlegroups.com> Bytes: 1886 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk 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.