Link to home
Start Free TrialLog in
Avatar of dkamdar
dkamdar

asked on

referencing an environment variable in .cc code

How can we reference or set an environment variable inside a .cc file?
Do we define them as macros?
How can it be defined. Please provide an example.
Is there an alternative?

Thanks
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dkamdar
dkamdar

ASKER

Hey jkr,

Thanks for the reply.
What is that _ before putenv for?
Beacause I saw my code uses putenv().
Can you please explain!

>>What is that _ before putenv for?

Ask MS :o)

Seriously, they tend to prepend underscores to (most) POSIX-compliant functions for an presumeably unknown reason...
just a small modification for Macro....

#include <stdlib.h>
#include <stdio.h>

#define ENVIRON getenv("PATH")
#define ENV_VAL(x) getenv(x)
int main()
{
 printf("Environment Path variable = %s", ENVIRON);
 printf("Environment Prompt Value = %s", ENV_VAL("PROMPT"));
return 0;
}

Avatar of dkamdar

ASKER

but hey ... I never told I am using MS?
I am on solaris machine.
Anyways i guess it just depends from copiler to compiler as far as naming the system functions go!

Thnaks arvind for that ... but i dont think I would want to compilicate it that way.