View Single Post
Old Nov 7th, 2006, 10:38 PM   #1
Ghosty
Newbie
 
Join Date: May 2005
Location: NJ
Posts: 18
Rep Power: 0 Ghosty is on a distinguished road
Send a message via AIM to Ghosty
setting env vars in unix

Please examine the following code:

#include <iostream>
#include <stdlib.h>

using namespace std;

int main(){

  char * envVar;
  envVar = getenv ("PS1");

  cout << "PS1 value is currently: " << *envVar << endl;
  cout << "We will now use putenv to change the PS1 variable" << endl;

  putenv("PS1=<duck>");

  envVar = getenv ("PS1");
  cout << "PS1 value is currently: " << *envVar << endl;
  return 0;
}

My book says that I have to use malloc aquire more space for "<duck>" but I've never used the malloc function. Can anyone tell me how to use malloc or now to use, perhaps, the new call?
Ghosty is offline   Reply With Quote