Hello guys,
my professor give me 2 days to study and make a program usign pipe, fork in c
i need to do a program
read a arq.txt
the father process read the file and the child print !
like this
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
int main (){
int std[2];
FILE *fp;
unsigned char c;
pipe(std);
if(fork() == 0){
close(0);
dup(std[0]);
close(std[0]);
close(std[1]);
exit(0);
}else{
close(1);
dup(std[1]);
close(std[0]);
close(std[1]);
if(fp = fopen("arq.txt", "rb")){
fscanf(fp, "%c", &c);
while(!feof(fp)){
fprintf(stdout,"%c",c);
fscanf(fp, "%c", &c);
}
fclose(fp);
}
wait(0);
}
return(0);
}
but the program doesn't work
and i dont know why