Sender: nate AT delorie DOT com Message-ID: <37DD8549.DF110F45@hmc.edu> Date: Mon, 13 Sep 1999 16:14:17 -0700 From: Nate Eldredge Organization: Harvey Mudd College X-Mailer: Mozilla 4.61 [en] (X11; U; Linux 2.2.12pre4 i586) X-Accept-Language: en MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: Re: load and save variable References: <00b401befefc$cbd992c0$5df343c3 AT marocky> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com Hakan Venderlof wrote: > > Hello > I would like to load an variable from a file > 'variable.txt' looking like this: > > 25 > > and then change the variable in a program and > save the variable to the samefile, eg overwriting the file > to for example > > 50 > > How should this be written? > > *** greetings grok sweden *** FILE *f; int v; f = fopen("variable.txt", "rt"); fscanf(f, "%d", &v); fclose(f); f = fopen("variable.txt", "wt"); fprintf(f, "%d\n", v); fclose(f); -- Nate Eldredge neldredge AT hmc DOT edu