#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
main(){
int p[2], pid, n, variable;
FILE * fentrada;
if ((fentrada = fopen("materiales.txt", "r")) == NULL){
printf("No se ha podido abrir el fichero materiales.txtn");
return (0);
}
pipe(p);
if ((pid=fork())==0){
close(p[1]);
close(0);
dup(p[0]);
close(p[0]);
while((n = (read(0, &variable, sizeof(variable)))) != 0){
write(1, &variable, sizeof(variable));
}
return(0);
}
while((n = (fscanf(fentrada,"%dn", &variable))) >= 0){
write(p[1], &variable, sizeof(variable));
}
fclose(fentrada);
}