📄 555.c
字号:
#include <sys/types.h>#include <sys/ipc.h>#include <sys/msg.h>#define MSGKEY 75struct msgform{ long mtype; char mtext [256]; double a,b,result; char opcode; int sender_pid;};main(){ struct msgform msg; int msgqid,pid,*pint; msgqid=msgget(MSGKEY,0777); pid=getpid();for(;msg.opcode!='q';){ printf("a="); scanf("%lf",&msg.a); printf("b="); scanf("%lf",&msg.b); printf("(+,-,*,/,q)="); msg.opcode=getchar(); while(msg.opcode=='\n') msg.opcode=getchar(); if(msg.opcode=='q')break; if('+'==msg.opcode||'-'==msg.opcode||'*'==msg.opcode||'/'==msg.opcode) { msg.mtype=1; msg.sender_pid=getpid(); msgsnd(msgqid,&msg,sizeof(struct msgform),0); msgrcv(msgqid,&msg,sizeof(struct msgform),pid,0); printf("client:msgqid=%d,receive from pid %d\n",msgqid,msg.sender_pid); printf("%lf %c %lf=%lf\n",msg.a,msg.opcode,msg.b,msg.result);} else printf("opcode is error");}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -