Questions tagged [getenv]

Anything related to C or C++ standard library functions `getenv` (C) or `std::getenv` (C++). These functions are used to get the value of an environment variable.

Anything related to C or C++ standard library functions getenv (defined in <stdlib.h> C standard header) or std::getenv (defined in <cstdlib> C++ standard header). These functions are used to get the value of an environment variable.

See CPPreference.com:

128 questions
-1
votes
1 answer

getenv() returns different values in different programs for the same environment variable

I am using ubuntu 14.04. I added the following code at the top of main() in a program, but I don't get anything printed when I run it. char const* masteruri = getenv("ROS_MASTER_URI"); if (masteruri!=NULL){ printf ("The current masteruri is:…
Sofia
  • 1
  • 1
  • 2
-1
votes
1 answer

Getenv() error when invoked more than one time

I have codes to get environment variable name from stand input and call library function getenv() to get the value and output. Here are codes. #include #include #include #define MAXLEN 256 int main(void) { char…
chaox
  • 51
  • 6
-1
votes
1 answer

getenv("HOME") returns "/root" with "sudo"

I'm writing a program on my Raspberry Pi that requires the function "getenv("HOME")" to locate "/home/pi". However, since I'm using the "wiringPi" library that requires "sudo" to run, "getenv("HOME")" now returns "/root" as the HOME directory…
K.Y. L
  • 3
  • 3
-1
votes
2 answers

Environment Variables in C

I know this type of question has been asked a lot but none of the answers seem to help. I set an environment variable through setenv() function call in Ubuntu Linux. However, the program doesn't seem use this environment variables. If I use…
tpar44
  • 1,431
  • 4
  • 22
  • 35
-2
votes
1 answer

secure_getenv function not giving the expected result

In my program I am using secure_getenv function to fetch some environment variables. I included stdlib.h in my program. This is the sample call to secure_getenv. Line 1 : char *myenv; Line 2 : myenv = __secure_getenv("DATA"); After the above lines…
-2
votes
1 answer

To print the environment from the stdin (var name) & execute the getenv() function it compiles correctly but no output what am i missing?

int main(int ac, char **av, char **env) { unsigned int i = 1; while(getenv("env[i]") != NULL) { printf("%s\n", env[i]); i++; } return 0; }
Dr.Nati M
  • 7
  • 3
-2
votes
1 answer

Where is the .env file stored for php

In some laravel the .env-file is heavily used to store the application configuration values. I am currently playing with a legacy project of mine and in a cronjob I am developing, I planned on testing out using .env to store information. Question…
Trond
  • 363
  • 1
  • 4
  • 14
-2
votes
1 answer

Segmentation fault on getenv C?

So what helps me when coding is collaberating everything i've learned into one random project. To better help me and understand when coding. I learnt about getenv a while back and was testing it. Worked fine until I went back to work on learning c…
John
  • 73
  • 2
  • 8
1 2 3
8
9