Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fcntl.h>
- #include <stdlib.h>
- #include <signal.h>
- #include <string.h>
- #include <stdio.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #define PNAME2 "tmpPipeInputChars"
- #define PNAME1 "tmpPipeOutputChars"
- int main(){
- int fd1, fd2;
- int pin = 0;
- char cod[10];
- char risposta[100];
- //creo le pipe se non sono già presenti
- mkfifo(PNAME2, 0666);
- mkfifo(PNAME1, 0666);
- //apro le pipe utilizzate
- if( ((fd1 = open(PNAME1, O_RDONLY)) < 0) || ((fd2 = open(PNAME2, O_WRONLY)) < 0)){
- perror("Errore appertura pipe");
- exit(EXIT_FAILURE);
- }
- while(pin <= 99999){
- sprintf(cod, "%d", pin);
- write (fd2,cod,strlen(cod)+1);
- int dim = 0;
- while((dim < 100) && read(fd1, &risposta[dim], 1) && (risposta[dim] != 0))
- dim ++; //accumulo il messaggio
- //printf("%d - %s", pin, risposta);
- if(strstr(risposta, "corretto")){
- printf("Pin trovato %d\n", pin);
- return 0;
- }
- pin++;
- }
- close(fd1);
- close(fd2);
- return 0;
- }
Add Comment
Please, Sign In to add comment