Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <sys/types.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #include <string.h>
- #include <stdlib.h>
- //PIN e POUT sono altri nomi delle pipe
- #define POUT "carPipeOut"
- #define PIN "carPipeIn"
- int main(){
- int round,fdin,fdout,bytesread,hole,car;
- char message[100];
- char answer[8];
- mkfifo(POUT,0666);
- mkfifo(PIN,0666);
- if ( (fdout = open (POUT,O_RDONLY)) < 0 ) { // apre la pipe in lettura
- perror("errore apertura pipe");
- exit(1);
- }
- if ( (fdin = open (PIN,O_WRONLY)) < 0 ) { // apre la pipe in lettura
- perror("errore apertura pipe");
- exit(1);
- }
- car=7;
- for(round=0;round<=20;round++){
- printf("*************\nround %d! Start!\n",round+1);
- strcpy(answer, "");
- bytesread = read(fdout,message,100);
- printf("Ho letto %d caratteri: %s\n",bytesread,message);
- sscanf(message,"%d#",&hole);
- while(hole!=car){
- if(hole<car){strcat(answer,"l"); car--;}
- else{strcat(answer,"r"); car++;}
- }
- printf("Scrivo %s\n",answer);
- write (fdin,answer,strlen(answer));
- }
- close(fdin); close(fdout);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement