msg_client.c
来自「Linux大学上机源码学习」· C语言 代码 · 共 34 行
C
34 行
#include <stdlib.h>#include <stdio.h>#include <string.h>#include <sys/ipc.h>#include <sys/msg.h>#define MSGKEY 75struct my_msg {long mtype; char text[256]; };main(){ struct my_msg msgbuf; int running=1; int msgid; long int msg_to_receive=0; msgid=msgget(MSGKEY,0777|IPC_CREAT); if(msgid==-1) { printf("error\n"); exit(0); } while(running) { printf("enter some text:"); fgets(msgbuf.text,256,stdin); msgbuf.mtype=1; if (msgsnd(msgid,(void*)&msgbuf,256,0)==-1) { printf(" msgsnd error\n"); exit(0);} if (strncmp(msgbuf.text,"end",3)==0) running=0;} exit(0);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?