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.
*char
shmget
shmat
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")
data->dir_name
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.
queue->directory[i]
"foo"
Thanks in advance!
, , . , . , data->dir_name queue->directory[i], , . , "foo". , , .
, , , strcpy .
strcpy
char directory[10][200];
strcpy (queue->directory[i], data->dir_name);
, 200 ( ) , . , , malloc; ; malloc ed , . Google , malloc .
malloc