[comp.binaries.ibm.pc.d] Environment variables and TurboC

gejohann@uokmax.UUCP (Gene Edward Johannsen) (07/19/89)

How do you get DOS environment variables into a TurboC program?

I am working on a program that reads a text file and I want the user to be 
able to tell the program where the text file is located at by setting an 
environment variable.

Thanks.

Gene from the home office in Oklahoma City.

jk0@image.soe.clarkson.edu (Jason Coughlin) (07/19/89)

From article <3510@uokmax.UUCP>, by gejohann@uokmax.UUCP (Gene Edward Johannsen):
> 
> How do you get DOS environment variables into a TurboC program?

See char *getenv( char * ) and void putenv( char * ) in the Turbo C
Reference Manual.  I hope you have the Turbo C Reference Manual :-).

--
-- 
--
Jason Coughlin
( jk0@sun.soe.clarkson.edu , jk0@clutx )

bobmon@iuvax.cs.indiana.edu (RAMontante) (07/19/89)

One way is to use the oft-overlooked third argument to main:

	int main(int argc, char **argv, char **env)
	{
		return 0;	/* ...or whatever... */
	}

env is an array containing all the environment variables.  I recently
posted a little utility called `printenv' which uses this to display any
or all environment variables' values.

See pp. 17-19, 24 in the TCv2.0 Reference Manual.