Mail Archives: djgpp/1996/08/13/08:15:27
Xref: | news2.mv.net comp.os.msdos.djgpp:7175
|
From: | "John M. Aldrich" <fighteer AT cs DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: interrupting with ctrl-C
|
Date: | Mon, 12 Aug 1996 20:27:12 -0700
|
Organization: | Three pounds of chaos and a pinch of salt
|
Lines: | 35
|
Message-ID: | <320FF610.1E13@cs.com>
|
References: | <4un5jr$9li AT due DOT unit DOT no>
|
NNTP-Posting-Host: | ppp219.cs.com
|
Mime-Version: | 1.0
|
To: | Elling Jacobsen <jacobsen AT kjemi DOT unit DOT no>
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Elling Jacobsen wrote:
>
> Hello,
> I have a program in which I write data records to a
> number of files. My problem is that when I interrupt
> the program using ctrl-C, the files are left empty. I guess
> the reason is that the data are kept in memory and are
> not dumped to file at interrupt? Is there any way to
> ensure that all data records are written to file at
> interrupt?
DJGPP (like most compilers) uses buffered i/o to reduce disk
interactions. To ensure that all data gets written to disk
even though a crash may occur, use the fflush() function. For
example:
FILE *fp = fopen( "foo.dat", "w" );
fprintf( fp, "My name is %s.\n", name );
fflush( fp );
Note also that data is also written when the internal buffers
are full, but you cannot count on this occurring, especially
with programs that write small chunks of data.
--
John M. Aldrich, aka Fighteer I <fighteer AT cs DOT com>
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS d- s+:- a-->? c++>$ U@>++$ p>+ L>++ E>+ W+>++ N++ o+ K? w(---) O-
M-- V? PS+ PE Y+ PGP- t+(-) 5- X- R+ tv+() b+++ DI++ D++ G e(*)>++++
h!() !r !y+()
------END GEEK CODE BLOCK------
- Raw text -