You're copying a string, so you can't just use assignment - you need strcpy:
#include <string.h>
...
strcpy(buf, argv[1]);
문제
I need to add to the shared memory string from arguments (ex. ./a.out abcxyz). I wrote the code, but it don't add string or don't show me string. What is the reason?
int main(int argc, char **argv){
int shmid;
char *buf;
shmid = shmget(KEY, 5, IPC_CREAT | 0600);
buf = (char *)shmat(shmid, NULL, 0);
*buf = argv[1];
printf("\n%c\n", buf);
return 0;
}
해결책
You're copying a string, so you can't just use assignment - you need strcpy:
#include <string.h>
...
strcpy(buf, argv[1]);