What does getenv() do and why would you use it?
getenv()?
Collapse
This topic is closed.
X
X
-
ProtomanTags: None -
Neelesh Bodas
Re: getenv()?
Protoman wrote:[color=blue]
> What does getenv() do and why would you use it?[/color]
man getenv.
It returns a pointer to the null terminated string having a value from
the environment.
#include <cstdlib>
#include <iostream>
int main()
{
std::cout << std::getenv("PW D") << std::endl;
}
-
S.Colancon
Re: getenv()?
This function can be used for example because you implement a new algorithm
and to keep the old algo you can define an envvar that will allow you to
switch between old and new algo. By this way you define an if(getenv(...))
to determine which algo will be run.
Stef
"Neelesh Bodas" <neelesh.bodas@ gmail.com> a écrit dans le message de news:
1133081999.6379 71.310040@g47g2 00...legr oups.com...[color=blue]
> Protoman wrote:[color=green]
>> What does getenv() do and why would you use it?[/color]
>
> man getenv.
>
> It returns a pointer to the null terminated string having a value from
> the environment.
>
> #include <cstdlib>
> #include <iostream>
> int main()
> {
> std::cout << std::getenv("PW D") << std::endl;
> }
>[/color]
Comment
-
Protoman -
Winbatch
Re: getenv()?
"Protoman" <Protoman2050@g mail.com> wrote in message
news:1133110322 .954929.19800@g 47g2000cwa.goog legroups.com...[color=blue]
> So, what's an enviroment variable and how do I define one?
>[/color]
What environment are you in? Windows or *nix?
Comment
-
Protoman
Re: getenv()?
Winbatch wrote:[color=blue]
> "Protoman" <Protoman2050@g mail.com> wrote in message
> news:1133110322 .954929.19800@g 47g2000cwa.goog legroups.com...[color=green]
> > So, what's an enviroment variable and how do I define one?
> >[/color]
> What environment are you in? Windows or *nix?[/color]
WinXP.
Comment
-
John Harrison
Re: getenv()?
Protoman wrote:[color=blue]
> Winbatch wrote:
>[color=green]
>>"Protoman" <Protoman2050@g mail.com> wrote in message
>>news:11331103 22.954929.19800 @g47g2000cwa.go oglegroups.com. ..
>>[color=darkred]
>>>So, what's an enviroment variable and how do I define one?
>>>[/color]
>>
>>What environment are you in? Windows or *nix?[/color]
>
>
> WinXP.
>[/color]
Settings/Control Panel/System/Advanced/Environment Variables
john
Comment
-
Niklas Norrthon
Re: getenv()?
"Protoman" <Protoman2050@g mail.com> writes:
[color=blue]
> So, what's an enviroment variable and how do I define one?[/color]
If you don't know, you don't need to know. It's all system specific, and really has nothing
to do with C++ (except being able to access it with the getenv function).
If you really want to know read the system documentation. On Unix, FreeBSD, Linux and similar
start with the man pages for the shell you use.
/Niklas Norrthon
Comment
-
Protoman
Re: getenv()?
For example, how would I beable to write a simple program that
determines the processor the program's executing on? Use WinXP's
enviroment variable PROCESSOR_ARCHI TECTURE?
Comment
-
Howard
Re: getenv()?
"Protoman" <Protoman2050@g mail.com> wrote in message
news:1133198126 .449214.140170@ o13g2000cwo.goo glegroups.com.. .[color=blue]
> For example, how would I beable to write a simple program that
> determines the processor the program's executing on? Use WinXP's
> enviroment variable PROCESSOR_ARCHI TECTURE?
>[/color]
Please include the text of the message to which you're responding. (I know
that you've been told -repeatedly - how to do this.)
To anwer your question: Ask in a windows newsgroup.
-Howard
Comment
-
Niklas Norrthon
Re: getenv()?
"Protoman" <Protoman2050@g mail.com> writes:
[color=blue]
> For example, how would I beable to write a simple program that
> determines the processor the program's executing on? Use WinXP's
> enviroment variable PROCESSOR_ARCHI TECTURE?[/color]
PROCESSOR_ARCHI TECTURE is not set to anything on my system, (which
isn't windows), but here is a program that reads the value of
the environment variable PATH that usually exist both in unix
and windows environments. I'm sure you are able to modify it to
suit your needs.
#include <stdlib.h> /* getenv */
#include <stdio.h> /* printf */
int main(void)
{
const char* key = "PATH";
const char* val = getenv(key);
if (val != NULL) {
printf("%s=%s\n ", key, val);
}
else {
printf("%s not set\n", key);
}
return 0;
}
Note that getenv returns a char pointer to the value of the
environment variable. You should not modify it's content, and
you must not release it's memory. If you wan't to do anything
with it you should copy it to a buffer that you have control
over.
/Niklas Norrthon
Comment
Comment