delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/09/13/20:52:22

Sender: nate AT delorie DOT com
Message-ID: <37DD8549.DF110F45@hmc.edu>
Date: Mon, 13 Sep 1999 16:14:17 -0700
From: Nate Eldredge <neldredge AT hmc DOT edu>
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>
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

- Raw text -


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