鱼C论坛

 找回密码
 立即注册
查看: 2737|回复: 1

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

[复制链接]
发表于 2016-3-16 23:46:31 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
#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 [10];
    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 出现以下错误:

%T7}CR8(QWO((H6JU%9G.png

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

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2016-3-17 11:17:56 | 显示全部楼层
求助啊
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-21 20:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表