⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messagequen.txt

📁 以 下 程 序 在 IBM RS/6000 小 型 机(AIX 操 作 系 统) 上 和IBM PC(UNIX 操 作 系 统) 上 分 别 调 试 通 过。 该 程 序 主 要 模 拟 根 据 帐
💻 TXT
字号:
/*请求方程序msgreq.c*/ 

#include

#include 

#include 

#include

#include 

static struct msgbuf1{

long mtype;

char mtext[100];

} sndbuf, rcvbuf, *msgp ;

extern int errno;

main(int argc, char **argv) 

{ int rtrn, msqid ;

char name[10];

double balance;

if (argc!=2){ fprintf(stderr,

"msgreq [01-99]\n"); exit(-1); }

if ( (msqid = msgget(0x888, IPC_CREAT|0660)) == -1 ){

fprintf(stderr, "msgget 888 failed !\n"); exit(-1);

}

msgp=&sndbuf;

sprintf(sndbuf.mtext,"%2.2s",argv[1]);

printf("输入4位帐号:"); 

scanf("%s",&sndbuf.mtext[2]);

sndbuf.mtext[6]=0;

msgp->mtype=666;

rtrn=msgsnd(msqid,msgp, strlen(sndbuf.mtext), 0);

if (rtrn==-1){

perror("msgsnd"); exit(-1);

}

msgp=&rcvbuf;

fprintf(stderr,"等待后台数据处理进程的回答....");

rtrn=msgrcv(msqid,msgp, 100, atoi(argv[1]), 0);

if(rtrn==-1){ perror("msgrcv"); exit(-1); }

sscanf(rcvbuf.mtext,"%[^|]|%lf",name,&balance);

printf("\n姓名=%s\n",name); 

printf("余额=%lf\n",balance);

}








/*服务方程序msgcenter.c*/

#include

#include

#include

#include

#include

static struct msgbuf1{

long mtype;

char mtext[100];

} sndbuf, rcvbuf , *msgp;

extern int errno;

main()

{ int rtrn, msgqid ;

char strbuf[100];

if ( (msqid = msgget(0x888, IPC_CREAT|0600)) == -1 ){

fprintf(stderr, "msgget 888 failed !\n"); exit(-1);

}

while(1) {

msgp=&rcvbuf;

fprintf(stderr,"等待前台进程的请求....");

rtrn=msgrcv(msqid, msgp, 100, 666 ,MSG_NOERROR);

if(rtrn==-1){ perror("msgrcv");exit(-1); }

msgp=&sndbuf;

sprintf(strbuf,"%2.2s\0",rcvbuf.mtext);

msgp->mtype=atoi(strbuf);

printf("\n输入帐号=%4.4s的帐户姓名:",&rcvbuf.mtext[2]); 

scanf("%s",sndbuf.mtext);

strcat(sndbuf.mtext,"|");

printf("输入该帐户余额:"); 

scanf("%s",strbuf);

strcat(sndbuf.mtext,strbuf);

rtrn=msgsnd(msqid,msgp, strlen(sndbuf.mtext), 0);

if (rtrn==-1){ perror("msgsnd"); exit(-1); }

}

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -