Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.03 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <sys/msg.h>
  5. #include <sys/types.h>
  6. #include <sys/ipc.h>
  7. #include <string.h>
  8.  
  9. #define CLEF 20
  10.  
  11. struct msgbuf {
  12. long mtype; //Type
  13. int a;
  14. int b;
  15. double resultat;
  16. char operande[1];
  17. int quitter;
  18. };
  19.  
  20. struct msgbuf msgp;
  21.  
  22. int main(void)
  23. {
  24.     int msid, a, b, quitter;
  25.  
  26.     msgp.resultat = 0.;
  27.     msqid = msgget((key_t)CLEF, 0); //créa message
  28.     printf("Link started !\n");
  29.     printf("a : ");
  30.     scanf("%d", &a);
  31.     printf("\nb : ");
  32.     scanf("%d", &b);
  33.     printf("\noperande : ");
  34.     fgetc(stdin);
  35.     scanf("%1[+-]s", msgp.operande);
  36.     fgetc(stdin);
  37.     printf("quitter apres le resultat (1 : oui\t0:non) : ");
  38.     scanf("%d", &quitter);
  39.     msgp.a = a;
  40.     msgp.b = b;
  41.     msgp.quitter = quitter;
  42.    
  43.     int type = (int)time();
  44.     msgp.mtype = type;
  45.     msgsnd(msqid, &msgp, sizeof(msgp), NULL);
  46.     msgrcv(msqid, &msgp, sizeof(msgp), (long)type, NULL);
  47.  
  48.     printf("%d %s %d = %lf", msgp.a, msgp.operande, msgp.b, msgp.resultat);
  49.     if(quitter == 1)
  50.         msgctl(msqid, IPC_RMID, IPC_NOWAIT);
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement