msg_client.c
来自「这是一个linux下的编程」· C语言 代码 · 共 43 行
C
43 行
//客户端的程序,发送消息的#include<stdio.h>#include<string.h>#include<stdlib.h>#include<sys/types.h>#include<sys/msg.h>struct my_message{ long int message_type; char text[1024];};int main(int argc,char **argv){ int msgid; int snd; int running=1; char buffer[1024]; struct my_message msg; memset(buffer,0,sizeof(buffer)); msgid=msgget((key_t)1234,IPC_CREAT|0666); while(running) { printf("Entry some txt!\n"); fgets(buffer,1024,stdin); strcpy(msg.text,buffer); printf("you input is :%s\n",msg.text); msg.message_type=1; if((strncmp(buffer,"end",3))==0) { running=0; } snd=msgsnd(msgid,(void *)&msg,1024,0); if(snd != 0) { printf("msgsnd is failure\n"); exit(0); } } return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?