-5

I want to set and get the value of environment variable in Linux using C. Can anyone tell me how to use the setenv environment variable.

I want the environment value to be set to zero, and while using the getenv that environment value should be 0?

Andy Obusek
  • 12,614
  • 4
  • 41
  • 62
  • possible duplicate of [Set environment variables in C](http://stackoverflow.com/questions/3416638/set-environment-variables-in-c) – Kara Jan 03 '14 at 18:34
  • http://stackoverflow.com/questions/3416638/set-environment-variables-in-c – splrs Jan 03 '14 at 18:34
  • There may be two different things called `setenv`, a shell command (available only if you're using csh or tcsh; other shells generally use `set` and `export` for the same purpose) and a C library function (whose man page you should read before trying to use it). See also `putenv()`. – Keith Thompson Jan 03 '14 at 18:40
  • @ChrisCleeland i mean the value zero – user3158318 Jan 03 '14 at 18:44

1 Answers1

2

Try to use putenv() instead of setenv(). A little substrac of the manpage says:

"The setenv() function inserts or resets the environment variable name in the current environment list. If the variable name does not exist in the list, it is inserted with the given value. If the variable does exist, the argument overwrite is tested; if overwrite is zero, the variable is not reset, otherwise it is reset to the given value."

A question, when you said zero, you are talking about zero character right?. You have to put a string there.

Abend
  • 589
  • 4
  • 14
  • I dont know how you are going to use it. But if you expect to use the environment variable after program execution in another program or in console, it is not going to work because you are in another session. The visibility of a EV is from the parent to child processes. – Abend Jan 03 '14 at 18:45