TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: JAMIE KOWINSKY
from: FRANK ADAM
date: 1998-02-04 23:16:00
subject: Enviorment variables

On Jan 31 21:24, 1998, Jamie Kowinsky of 1:129/230 wrote:
G'day Jamie,
JK> Can anyone post some sample code on how to read enviorent vars from
JK> the current enviorment, and if possible how to modify them?
Look up the getenv() putenv() functions..pretty straight forward.
Anyway here is the BC example of it. 
BTW while getenv() is,  putenv() isn't ANSI/ISO and may or may not be 
available in your compiler.
#include 
#include 
#include 
#include 
#include 
int main(void)
{
   char *path, *ptr;
   int i = 0;
   /* get the current path environment */
   ptr = getenv("PATH");
   /* set up new path */
   path = (char *) malloc(strlen(ptr)+15);
   strcpy(path,"PATH=");
   strcat(path,ptr);
   strcat(path,";c:\\temp");
   /* replace the current path and display current environment */
   putenv(path);
   while (_environ[i])
       printf("%s\n",_environ[i++]);
   return 0;
}
The changes are only effective until program termination, and other processes 
will use the system's normal environment. IOW, if you spawn a child you have 
to supply your preferred environment to it as well.
 Regards, Frank.   Email: fadam@sensation.net.au. 
--- Msged 4.20 beta 4
---------------
* Origin: The ticking point, Melbourne, Australia. (3:635/728.21@fidonet)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.