Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/msg.h>
- #include <sys/types.h>
- #include <sys/ipc.h>
- #include <string.h>
- #define CLEF 20
- struct msgbuf {
- long mtype; //Type
- int a;
- int b;
- double resultat;
- char operande[1];
- int quitter;
- };
- struct msgbuf msgp;
- int main(void)
- {
- int msid, a, b, quitter;
- msgp.resultat = 0.;
- msqid = msgget((key_t)CLEF, 0); //créa message
- printf("Link started !\n");
- printf("a : ");
- scanf("%d", &a);
- printf("\nb : ");
- scanf("%d", &b);
- printf("\noperande : ");
- fgetc(stdin);
- scanf("%1[+-]s", msgp.operande);
- fgetc(stdin);
- printf("quitter apres le resultat (1 : oui\t0:non) : ");
- scanf("%d", &quitter);
- msgp.a = a;
- msgp.b = b;
- msgp.quitter = quitter;
- int type = (int)time();
- msgp.mtype = type;
- msgsnd(msqid, &msgp, sizeof(msgp), NULL);
- msgrcv(msqid, &msgp, sizeof(msgp), (long)type, NULL);
- printf("%d %s %d = %lf", msgp.a, msgp.operande, msgp.b, msgp.resultat);
- if(quitter == 1)
- msgctl(msqid, IPC_RMID, IPC_NOWAIT);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement