473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

getenv()?

What does getenv() do and why would you use it?

Nov 27 '05 #1
10 5639
Protoman wrote:
What does getenv() do and why would you use it?


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("PWD") << std::endl;
}

Nov 27 '05 #2
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" <ne***********@gmail.com> a écrit dans le message de news:
11**********************@g47g2000cwa.googlegroups. com...
Protoman wrote:
What does getenv() do and why would you use it?


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("PWD") << std::endl;
}

Nov 27 '05 #3
So, what's an enviroment variable and how do I define one?

Nov 27 '05 #4

"Protoman" <Pr**********@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
So, what's an enviroment variable and how do I define one?

What environment are you in? Windows or *nix?
Nov 27 '05 #5

Winbatch wrote:
"Protoman" <Pr**********@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
So, what's an enviroment variable and how do I define one?

What environment are you in? Windows or *nix?


WinXP.

Nov 27 '05 #6
Protoman wrote:
Winbatch wrote:
"Protoman" <Pr**********@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googleg roups.com...
So, what's an enviroment variable and how do I define one?


What environment are you in? Windows or *nix?

WinXP.


Settings/Control Panel/System/Advanced/Environment Variables

john
Nov 28 '05 #7
"Protoman" <Pr**********@gmail.com> writes:
So, what's an enviroment variable and how do I define one?


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
Nov 28 '05 #8
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_ARCHITECTURE?

Nov 28 '05 #9

"Protoman" <Pr**********@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
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_ARCHITECTURE?


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
Nov 28 '05 #10
"Protoman" <Pr**********@gmail.com> writes:
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_ARCHITECTURE?


PROCESSOR_ARCHITECTURE 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
Nov 29 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: JDJones | last post by:
I am trying to write a PHP action into my custom 404 error page that will email me when someone tries to access a bad link. I can get it to work and tell me the person's IP using <$ip = getenv...
1
by: Sims | last post by:
Hi, if i use... // php $info = getenv("HTTP_USER_AGENT"); // I noticed that Mozzila and Netscape <6(?) both use the same Agent. // so i was thinking of if...
2
by: Martoni | last post by:
Is there a variable to fetch with getenv that gives you the client host name. I can't find it in my docs so I suppose there isn't but it would be handy to be able to insert the "computer name" of...
0
by: Xavier | last post by:
Greetings, While messing around with the "dl" module I ran into a segfault. *DO NOTE THAT THE FOLLOWING OCCURED ON 2 OF MY LINUX WORKSTATIONS* ------ # python -c 'import dl;...
1
by: vertigo | last post by:
Hello i need to read $PATH variable for all users. I wanted to use something like setuid() and getenv() in C. Are there similar functions here ? (if not how can i do it ?) Thanx Michal
5
by: Chad Paquette | last post by:
Hi, We have a legacy cgi app that's written in C. We are encountering an error when we try to retrieve a cgi environment variable. The variable we are getting contains a Base64 encoded...
17
by: Protoman | last post by:
Why does getenv work backwards? When I'm testing an env variable, I have to test if its NOT equal to, rather than equal to, to get the desired result. As evidenced by this simple piece of code: ...
5
by: silrandir | last post by:
when attempting to call getenv() in global memory (c/c++), it constantly returns null, but when called in main, it properly reads the environment. is this expected behavior? sample code:...
4
by: Yogi Watcher | last post by:
Hi, Recently I have observed some odd behavior of getenv and putenv function. I am developing some code that integrates with several other libraries. This program is not using MFC. It is plain C...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.