📄 server2.txt
字号:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#define MSGKEY 75
struct my_msg
{long mtype;
char text[256];
};
main()
{ struct my_msg msgbuf;
int running=1;
int login=1;
char username[10];
char password[5];
int msgid;
long int msg_to_receive=0;
msgid=msgget(MSGKEY,0777|IPC_CREAT);
if(msgid==-1)
{ printf("error\n");
exit(0);
}
while(login)
{
printf("Please Enter the username:");
scanf("%s",username);
printf("\nPlease Enter the password:");
scanf("%s",password);
if((strncmp(username,"jsj051070",9)==0)&&(strncmp(password,"123",3)==0))
{
printf("\nLogin Successfull\n");
login=0;
}
else
{
printf("\nLogin Fail,please try again!\n");
}
}
while(running)
{
printf("enter some text:");
fgets(msgbuf.text,256,stdin);
msgbuf.mtype=1;
if (msgsnd(msgid,&msgbuf,256,0)==-1)
{ printf(" msgsnd error\n");
exit(0);}
if (strncmp(msgbuf.text,"end",3)==0)
running=0;
if (msgrcv(msgid,&msgbuf,256,msg_to_receive,0)==-1)
{ printf(" msgrcv error\n");
exit(0);}
printf("you wrote:%s",msgbuf.text);
if (strncmp(msgbuf.text,"end",3)==0)
running=0;
}
if(msgctl(msgid,IPC_RMID,0)==-1)
{ printf("msgctl(IPC_RMID)error");
exit(1);
}
exit(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -