Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Link Soal : https://www.dropbox.com/s/sse2lot7e6ohdl9/O1-T0316-RG01-09.pdf?dl=0
- #include <stdio.h>
- #include <sys/sem.h>
- #include <sys/ipc.h>
- #include <sys/shm.h>
- #include <sys/types.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- struct data{
- char pilih[10];
- };
- int main(){
- struct sembuf s;
- int h=shmget(123456, sizeof(struct data),IPC_CREAT|0666);
- int e=semget(123456,1,IPC_CREAT|0666);
- struct data *suit=(struct data*)shmat(h,NULL,066);
- semctl(e,0,SETVAL,0);
- int flag=0;
- do{
- do{
- flag=0;
- printf("Masukan Pilihan[batu|gunting|kertas] : ");
- scanf("%[^\n]",suit->pilih);getchar();
- if(strcasecmp(suit->pilih,"batu")==0||strcasecmp(suit->pilih,"kertas")==0||strcasecmp(suit->pilih,"gunting")==0)
- flag=1;
- else if(strcasecmp(suit->pilih,"exit")==0)
- break;
- }while(flag==0);
- s.sem_num=0;
- s.sem_op=1;
- s.sem_flg=0;
- semop(e,&s,1);
- printf("Press Enter");
- getchar();
- }while(strcasecmp(suit->pilih,"exit")!=0);
- shmdt(&s);
- shmctl(h,IPC_RMID,0);
- semctl(e,0,IPC_RMID);
- return 0;
- }
Add Comment
Please, Sign In to add comment