Assigning strings in shared memory processes

I am new to C and this is my first question, so forgive my ignorance.

I have a program that needs to share a chain between two processes. I declared a structure containing an array *char. This structure is released shmgetand shmatbefore the main process is branched.

typedef struct Queue
{
    int index;
    char *directory[10];
} Queue;

In one of the processes, I try to set the value: ( data->dir_nameis *charfor a line 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 configured queue->directory[i]for "foo"another process, it sees this. However, passing value data->dir_nameis not the case.

Thanks in advance!

+5
source share
1 answer

, , . , . , data->dir_name queue->directory[i], , . , "foo". , , .

, , , strcpy .

char directory[10][200];

strcpy (queue->directory[i], data->dir_name);

, 200 ( ) , . , , malloc; ; malloc ed , . Google , malloc .

+5

All Articles