I need to write to shared memory, thus I have
#define FLAGS IPC_CREAT | 0644
int main() {
key = ftok("ex31.c", 'k');
shmid = shmget(key, 3, FLAGS);
shmaddr = shmat(shmid,0,0); // THOSE LINES WORK AS EXPECTED
char* userInput = malloc(5);
read(0, userInput, 3); // I want to read "b34" for example, WORKS GOOD
strcpy(shmaddr,userInput); // THROWS EXCEPTION!
}
it throws me exception in strcat
, and if I delete it the exception is thrown in the next line of strcpy
.
I need to write to the memory "b34\0
" (4 chars) and then read it.