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>
- #define POUT "tmpPipeInput"
- #define PIN "tmpPipeOutput"
- void die(char *s) {
- perror(s);
- exit(EXIT_FAILURE);
- }
- int main() {
- int out;
- int in;
- int codice = 0;
- char leggi[100];
- mkfifo(POUT,0666); // crea la pipe, se esiste gia' non fa nulla
- mkfifo(PIN,0666); // crea la pipe, se esiste gia' non fa nulla
- if ( (out = open(POUT,O_RDWR)) < 0 )
- die("errore apertura pipe\n");
- if ( (in = open(PIN,O_RDWR)) < 0 )
- die("errore apertura pipe\n");
- while(codice < 99999){
- write(out, &codice, sizeof(int));
- int r=0;
- while ( r<100 && read(in, &leggi[r], 1 ) && leggi[r] != 0 )
- r++;
- if (leggi[4] == 'c'){
- printf("il pin corretto รจ:%d\n", codice);
- return 0;
- }
- codice++;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment