Article View: comp.os.msdos.programmer
Article #1920Re: Help needed for sharing common data between programs
From: Dead Dog
Date: Fri, 17 Aug 1990 02:33
Date: Fri, 17 Aug 1990 02:33
31 lines
1737 bytes
1737 bytes
klg0582@uxa.cso.uiuc.edu (Ken-Huang Lin) writes:
> I would like to have some "global variables" remain alive even after the
> program ends so that the next program can access them. I tried to set
> environment variables inside the program using
> system("set v=...");
> in Turbo C. Unfortunately, the effect is only local to that program. Is
> there any way to set the global environment variables in a program? Or is
> there a better way to serve the same purpose?
There is a way you can search backward through memory blocks and find the
"real" environment table, but there is a much better way. Write the
variables into a file...
int write_vars()
{
FILE *f;
f=fopen("globvar.dat","wb");
if (f==NULL) return 0; /* error creating file */
fprintf(f,"%d\n",v);
fprintf(f,"%s\n",misc_string);
/* ... */
fclose(f);
}
Then read them in with your second program.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"The laugh of the king was clear :Dead Dog (Robey)
and strong, so out of fear the 4 @6555 (wwivnet)
crowd laughed along." -Tony Banks ..!rti!tijc02!kk4fs!deadog
Technical Details
Message-ID:
<Za01N1w162w@kk4fs.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!samsung!emory!mephisto!mcnc!rti!olympus!kk4fs!deadogReferences:
<1990Aug9.042244.6@ux1.cso.uiuc.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!samsung!emory!mephisto!mcnc!rti!olympus!kk4fs!deadog From: deadog@kk4fs.UUCP (Dead Dog) Newsgroups: comp.os.msdos.programmer Subject: Re: Help needed for sharing common data between programs Message-ID: <Za01N1w162w@kk4fs.UUCP> Date: 17 Aug 90 02:33:46 GMT References: <1990Aug9.042244.6@ux1.cso.uiuc.edu> Distribution: comp.os.msdos.programmer Organization: KK4FS - Free Speech Forum, +1 615 283 0864 for BBS Lines: 31