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
Do we define them as macros?
How can it be defined. Please provide an example.
Is there an alternative?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>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...
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;
}
#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;
}
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.
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.
ASKER
Thanks for the reply.
What is that _ before putenv for?
Beacause I saw my code uses putenv().
Can you please explain!