I've got some difficulties with this code. I need to get all the information from the pipe at its end. But, I get a segfault error.
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
int main(void){
int tube[2];
if(pipe(tube) == -1){
perror("Erreur");
exit(1);
}
dup2(tube[1],1);
printf("Few lines \n");
printf("of an undefined size. \n");
while (!feof(tube[0])) {
char temp = fgetc(tube[0]);
printf("chaine : %c\n", temp);
}
return 0;
}
If you have an idea of how I can handle this problem, please explain.