urgent advice needed - gcc

what does the statement :

static char a[100] = "a";

store in the executable image. ??

I need to make a command line parameter exist AFTER the program finishes execution.. so that when i run the code next time ( without recompiling ).. i can work with the paramter..

for example:

$./prog pipe
>hello

$./prog tyre
>pipe

$./prog foo
>pipe

Also, i dont want to store it in another file.. maybe i could write a copy of prog in memory..

I hope u got what i wanna do ..

basically how to make

int main()
{ static char a[100[]="hello";
printf("%s",a);
}

to print pipe instead of hello... i think thats what static does.. but does it remember values even when prog execution ends.. i doubt that :frowning:

static essentially means the data is stored in heap memory, and that the variable cannot be seen outside the code - file scope it is called.

You want data to persist from one invocation of a compiled file to the next? Right?
Well when your code exits, all of the memory is reclaimed by the system. Your data is lost. The only ways to do this:

  1. have a process running all the time - itt stores the data in an environment variable
  2. store the data in a file
  3. Enter the value as a parameter when the process starts.

static essentially means the data is stored in heap memory, and that the variable cannot be seen outside the code - file scope it is called.

You want data to persist from one invocation of a compiled file to the next? Right?
Well when your code exits, all of the memory is reclaimed by the system. Your data is lost. The only ways to do this:

  1. have a process running all the time - itt stores the data in an environment variable
  2. store the data in a file
  3. Enter the value as a parameter when the process starts.

Then i guess the options are to either to create another process using fork/exec or... maybe use system(..) and create a replicated program.

In any ways... your suggestion is right.. but i was wondering if we were not to use files... is their anyway to get the data back from the "executable image" using any command or code?

This is because when we make a static char * variable... does it not retain the data in the executable image from one execution to the next.

I solved the prob using files.. but files = disk ... i want to retrieve from the RAM> if there is someway to do that ?

Then create a ramdisk, mount it somewhere and use the code you've created for solving the problem using files.

Why don't you set an environmet variable from you program?

Hey Roman.. i am not sure environment variables are carried over from one execution of the program to the next IF they are running on two DIFFERENT shells...

I am using system() to call the the copy program from the original.. and i think system calls that in a different shell. i thought of environ earlier.