默.默 发表于 2016-3-16 23:46:31

编写消息队列传送结构体数据

#include<sys/utsname.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/msg.h>
#include <csapp.h>

typedef struct STU{
    char name ;
    int age;
    float height;
}*st;

typedef struct {
    long int my_msg_type;
    st info;
}my_msg_st;

int main(){
    int msgid;
    struct my_msg_st some_data;
    struct STU stu;

    msgid = msgget((key_t)1234, 0666 | IPC_CREAT);
    if (msgid == -1){
    fprintf(stderr,"msgget failed with : %d\n",errno);
    exit(EXIT_FAILURE);
    }
    strcpy(stu.name,"张三");
    stu.age = 20;
    stu.height = 1.75;
   
    some_data.info = &stu;
    some_data.my_msg_type = 1;

    if (msgsnd(msgid,(void *)&some_data,sizeof(some_data), 0) == -1 ){
      fprintf(stderr,"msgsnd failed\n");
      exit(EXIT_FAILURE);
    }
   exit(EXIT_FAILURE);
}

在Ubuntu14.04.4系统下GCC 出现以下错误:



请求解答一下,今天一天都在解决这个问题,可以说找不到解决的方法

默.默 发表于 2016-3-17 11:17:56

求助啊
页: [1]
查看完整版本: 编写消息队列传送结构体数据