View Single Post
Old Nov 8th, 2006, 9:02 PM   #8
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 894
Rep Power: 4 The Dark is on a distinguished road
When i said "If you made a function using this code" i meant making the code as shown into a function (e.g. by changing the name from main to something else), not making some of the code into a function, but somehow leaving the variables in the main function. Sorry if that wasn't clear.

Ghosty, you can use new in the same way as malloc, in this case you could use something like:
  const char *eName = "PS1";
  const char *eVal = "<duck>";
  char *name = new char [strlen(eName) + 1 + strlen(eVal) + 1];
  strcpy (name, eName);
  strcat (name, "=");
  strcat (name, eVal);
  putenv(name);

I am not sure when you could delete the memory - from the man page I read, it seemed you could only delete it when you set the PS1 variable to something else.
The Dark is offline   Reply With Quote