I have a program that needs to share a string between two processes. I have declared a struct that contains an array of *char. This struct is allocated with shmget and shmat before the main process is forked.
typedef struct Queue
{
int index;
char *directory[10];
} Queue;
In one of the processes, I try to set the value: (data->dir_name is a *char to a string such as "/data1")
queue->directory[i] = data->dir_name; // Option 1
queue->directory[i] = "foo"; // Option 2
My question is, what is the difference between the first and second statements above? When setting the queue->directory[i] to "foo", the other process sees it. However, passing the value data->dir_name, it does not.
Thanks in advance!
free(data->dir_name)somewhere before usingqueue->directory[i]? Alsodata->dir_namemaybe an automatic variable.