📄 c1.c
字号:
#include<sys/types.h>#include<sys/ipc.h>#include<sys/msg.h>#include<stdio.h>#include<stdlib.h>#include<string.h>#define MSGKEY 75struct msgform{ long mtype; int action; char user[10],pass[20]; float num1,num2,rs; char op; char mtext[256]; };main(){ struct msgform msg; int msgqid,pid,*pint; char ch; char pw1[20],pw2[20];printf("************************\n"); printf("***WELCOME TO OUT SYSTEM***\n"); printf("************************\n");for(;;){ msg.action=0;printf("*******input 1: LOAD SYSTEM \n"); printf("*******input 2: NEW USER\n"); printf("*******input q: EXIT\n"); while((ch=getchar())=='\n'); printf("%c\n",ch);switch(ch) { case '1': // load();printf(">>INPUT USERNAME:>>\n"); scanf("%s",msg.user); printf(">>INPUT PASSWORD:>>"); scanf("%s",msg.pass); msg.action=1; break; case '2': // new();printf(">>INPUT USERNAME:>>\n"); scanf("%s",msg.user); printf(">>INPUT PASSWORD:>>"); scanf("%s",pw1); printf(">>INPUT PASSWORD AGAIN:>>"); scanf("%s",pw2); if(strcmp(pw1,pw2)==0) {strcpy(msg.pass,pw1);msg.action=2;printf("dd");} else {printf("d");} break; case 'q': printf("*** THANK YOU FOR YOUR USING ***\n"); exit(0); default: printf("PLEASE INPUT THE RIGHT CHAR\n"); exit(0); } msgqid=msgget(MSGKEY,0777); pid=getpid();pint=(int *)msg.mtext; *pint=pid; msg.mtype=1; msgsnd(msgqid,&msg,sizeof(struct msgform),0); msgrcv(msgqid,&msg,512,pid,0); printf("receive:aciton=%d\n",msg.action);if(msg.action==3) { printf("load success...\n"); msg.action=10; }else if(msg.action==4){ printf("zhece success...\n"); msg.action=10;}else if(msg.action==-1){ printf("wrong username or password\n");}else if(msg.action==-2){printf("THIS NAME IS ALREADY EXIST\n");}if(msg.action==10){ printf("***NOW LET'S BEGING...***\n"); for(;;) { printf("*** TYPE q FOR EXITING,ELSE FOR CONTINUE ***\n"); while((ch=getchar())=='\n'); if(ch=='q') break; printf(">>Please input oprator number1: "); scanf("%f",&msg.num1); printf("read %f\n",msg.num1); printf(">>Please input oprator (+,-,*,/): "); for(;;){ ch=getchar(); if(ch=='+' || ch=='-'|| ch=='*' || ch=='/') break;} printf("%c\n",ch);msg.op=ch; printf(">>Please input oprator number2: "); scanf("%f",&msg.num2); printf("read %f\n",msg.num2); pint=(int *)msg.mtext; *pint=pid; msg.mtype=1; msgsnd(msgqid,&msg,sizeof(struct msgform),0); msgrcv(msgqid,&msg,512,pid,0); printf("client :receive from pid%d\n",*pint); printf("ANSWER COMED FROM SERVER : %f\n", msg.rs); } }}}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -