This repository has been archived on 2026-05-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
prog-104-p-04-2030/AnimalProcessing/Proficiencies/double_pipe.c
T
2026-04-16 16:11:49 +02:00

104 lines
1.7 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
#include <sys/types.h>
#include <err.h>
/*
__
___( o)>
\ <_. )
`---'
Coic Coic
*/
void clc(int n){
int pipe1[2];
int pipe2[2];
if(pipe(pipe2) == -1) return;
if(pipe(pipe1) == -1) return;
pid_t pid = fork();
if(pid < 0) return;
//Child
if(pid == 0) {
while(1){
if(pipe1[0] != NULL) pipe2[1] = n* n;
}
}
//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]);
return;}
pipe1[1] = n;
wait(NULL); //on attends le Child
printf("The Oracle says the square is: %i", pipe2[0]);
}
}
int main() {
/*
//[0] -> lecture | [1]-> ecriture
int pipe1[2];
int pipe2[2];
if(pipe(pipe1) == -1) return 1;
if(pipe(pipe2) == -1) return 1;
pid_t pid = fork();
if(pid < 0) return 1;
//Child
else if (pid == 0) {
}
//Teacher ? WTF what are you doing here ?
else{
close(pipe1[0]);
close(pipe2[1]);
char buffer[2048];
fgets(buffer, 2047, stdin);
if(strcmp(buffer, "-1") == 0){
close(pipe2[0]);
close(pipe1[1]);
return 1;
}
pipe1[1] = buffer;
}*/
}