1

我的程序有小问题。不知道为什么启动程序的时候会弹出Segmentation fault (core dumped) My code for client.c

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ipc.h>
#include <stdlib.h>
#include <string.h>

#define receiveKey 21
#define sendKey 11

int main(int argc, char *argv[])
{
    char msg[512];
    strcpy(msg, argv[1]);
    key_t key;
    key=ftok("/Downloads/zad6", getpid());

    int senQueue=msgget(sendKey,0777);
    int recQueue=msgget(receiveKey,0777);

    msgsnd(senQueue,&msg,strlen(msg),0);
    msgrcv(recQueue,&msg,sizeof(msg),0,0);

    printf("Translate result: %s\n", msg);
    return 0;    }
4

0 回答 0