Setting Environment Variable date

Hi to all...

I'm currently running a C++ program in Unix environment and it is dependent to a Unix environment variable with a date value.

ex: echo $DateToday
20060403

I want to change that date in my C++ program, changing the value date to 20061120 and revert back to original date after the processing is done.

Any idea on this?

Many thanks
-d3ck

You can use getenv and setenv C library functions to do this. In case there is a problem with C++ strings in a C function, you can refer this post from Corona688.

i tried to use

int putenv(const char *"DateToday=20061120");

but i'm getting an error message of "parse error before string constant" according to my research i just have to declare #inclued <stdio.h> but the error still appear during compilation.

i also tried

int setenv(const char *DateToday, const char *20061120, int rewrite);

but it seems that it dont accept date or numerical value.

with regard to the post of Corona688, what's that all about? i'm a bit confused.

thanks for the help...

Many thanks,
-d3ck

Exactly why I asked you to take a look at Corona688's post. When you putenv is a C function, so you cannot use C++ strings in it. Maybe you could declare the string before you call the function, then try something like:

putenv(stringname.c_str());

i see

i'm thinking of something like this

String xdate = "DateToday=20061120";
int putenv(const char *xdate.c_str());

that's my interpretation, please correct me if im wrong... im not in my workstation right now.

Many thanks,
-d3ck

Why do you need that "const char *"? Try it without that.

oks ill try that...

thanks for your help...