diff --git a/AnimalProcessing/Proficiencies/autre.c b/AnimalProcessing/Proficiencies/autre.c new file mode 100644 index 0000000..121f141 --- /dev/null +++ b/AnimalProcessing/Proficiencies/autre.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include +#include +#include + + + +void clc(){ + + + //pipes + int pipe1[2];// PIPE A + int pipe2[2];// PIPE B + if(pipe(pipe1) == -1) return; + if(pipe(pipe2) == -1) return; + + + char buffer[2048]; + char buffer2[2048]; + //fgets(buffer, 2047, stdin); + + + pid_t pid = fork(); + + if(pid < 0) return; + if (pid == 0){ + + while(read(pipe1[0],buffer ,2047 )){ + int n = atoi(buffer); + + if(n == -1) exit(0); + char buf = n *n; + + write(pipe2[1], &buf , 1); + + + } + } + + else{ + + read(pipe2[0], buffer2, 2048); + if(strcmp(buffer2, "-1") == 0) { + + close(pipe1[0]); + close(pipe1[1]); + close(pipe1[0]); + close(pipe1[1]); + return; + } + printf("The Oracle says the square is: %s\n", buffer2); + } +} + +int main(){ + + clc(); + + +} diff --git a/AnimalProcessing/Proficiencies/double_pipe.c b/AnimalProcessing/Proficiencies/double_pipe.c index 7c64751..98af798 100644 --- a/AnimalProcessing/Proficiencies/double_pipe.c +++ b/AnimalProcessing/Proficiencies/double_pipe.c @@ -14,14 +14,20 @@ ___( o)> Coic Coic */ -void clc(int n){ +void clc(){ + int n = 0; int pipe1[2]; - int pipe2[2]; + int pipe2[2]; + char buffer[2048]; if(pipe(pipe2) == -1) return; if(pipe(pipe1) == -1) return; + fgets(buffer, 2047, stdin); + n = atoi(buffer); + pipe1[1] = n; + pid_t pid = fork(); if(pid < 0) return; @@ -31,19 +37,16 @@ void clc(int n){ while(1){ - if(pipe1[0] != NULL) pipe2[1] = n* n; + if(pipe1[0]){ + pipe2[1] = n* n; + exit(0); + } } } //Teacher ? WTF what are you doing with my uncle ? Why do you have an eggplant in your right hand and a riding whip in your left hand ? WTF is going on here else { - char buffer[2048]; - - fgets(buffer, 2047, stdin); - int n = 0; - n = atoi(buffer); - if(n == -1) { close(pipe1[0]); close(pipe2[1]); @@ -53,13 +56,15 @@ void clc(int n){ wait(NULL); //on attends le Child - printf("The Oracle says the square is: %i", pipe2[0]); + printf("The Oracle says the square is: %i\n", pipe2[0]); } } int main() { + clc(); + /* //[0] -> lecture | [1]-> ecriture int pipe1[2]; diff --git a/AnimalProcessing/Proficiencies/test b/AnimalProcessing/Proficiencies/test new file mode 100755 index 0000000..2c08d6b Binary files /dev/null and b/AnimalProcessing/Proficiencies/test differ