Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <sys/ipc.h>
  2. #include <sys/msg.h>
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <string.h>
  6. #include <sys/types.h>
  7.  
  8. int sum;
  9. int mno;
  10. int roz;
  11. int dev;
  12.  
  13. void suma ()
  14. {
  15. sum=a+b
  16. };
  17.  
  18. void mnozenie ()
  19. {
  20. mno=a*b
  21. };
  22.  
  23. void roznica ()
  24. {
  25. roz=a-b
  26. };
  27.  
  28. void dzielenie ()
  29.  
  30. {
  31. dev=a/b
  32. };
  33.  
  34. void wyswietlanie ()
  35. {
  36.  
  37. };
  38.  
  39.  
  40. typedef struct {
  41. long type;
  42. char tresc[1000];
  43. } komu;
  44.  
  45.  
  46. void nadawca(int kolejka){
  47. komu k;
  48.  
  49. k.type=1;
  50. strcpy(k.tresc, "ala ma kota");
  51. msgsnd(kolejka,&k , sizeof(komu),IPC_NOWAIT);
  52.  
  53. }
  54.  
  55.  
  56. void odbiorca(int kolejka){
  57. komu k;
  58. msgrcv(kolejka, &k, sizeof(komu),1,0);
  59. printf("%s",k.tresc);
  60. msgctl(kolejka,IPC_RMID,NULL);
  61.  
  62. }
  63.  
  64. int main(){
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72. pthread_t threads [5];
  73.  
  74. pthread_create(&threads[0], NULL, suma, 0);
  75. pthread_create(&threads[1], NULL, roznica, 0);
  76. pthread_create(&threads[2], NULL, mnozenie, 0);
  77. pthread_create(&threads[3], NULL, dzielenie, 0);
  78. pthread_create(&threads[4], NULL, wyswietlanie, 0);
  79.  
  80. int num;
  81. int number[10];
  82. char c;
  83. int i = 0;
  84. while((c = getchar()) !=EOF)
  85. {
  86. if(c == ' ' || c == '\n')
  87. {
  88. number[i++] = '\0";
  89. num = atoi(number);
  90. printf("%d\n", num);
  91. i=0;
  92. }
  93. else
  94. {
  95. number[i++] = c;
  96. }
  97. }
  98. return 0;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement