- 论坛徽章:
- 0
|
code]
struct mymsgbuf{
long mtype;/*Message type*/
int request;/*Work request number*/
float salary;/*Employee's salary*/
}msg,rmsg;
msg.mtype=1;
msg.request=1;
msg.salary=55.00;
已将此消息成功送到消息中:
[root@lx linux_c]# ipcs
------ Message Queues --------
key msqid owner perms used-bytes messages
0x6d0690dc 262152 root 660 8 1
定义的读函数:
int read_message(int qid,long type,struct mymsgbuf* qbuf)
{
int result,length;
/*The length is essentially the size of the structure minus sizeof(mtype)*/
length=sizeof(struct mymsgbuf)-sizeof(long);
printf("%d\n",length);
if((result=msgrcv(qid,qbuf,length,type,0))==-1){
return(-1);
}
return(result);
}
在main中:
if((length=read_message(qid,0,&rmsg))==-1){
perror("send_message" ;
exit(1);
}
printf("mtype:%drequest:%d,salary:%ld",rmsg.mtype,rmsg.request,r
msg.salary);
输出结果:
mtype:1request:1,salary:0
不知为什么slary等于0呢
大侠帮忙看看吧,
//bow
[/code][/quote] |
|