i'm facing a problem with reading from two input files with two children. The two children should read alternately a word from each file, sending them to the parent that will output them like this:
input1: "I really"
input2: "am stupid"
output: "I am really stupid"
How can i do that using the functions open (for opening the input file for reading) and read? The "son" function for the children (There will be two similar function for the children, one that reads the even words and one that reads the odd words) should be something like this:
void son(char i_file, int p[2], int bro_pid){
int c,fd=open("i_file", O_RDONLY, S_IWUSR);
char buf;
if(fd > 0){
close(p[0]);
while(c=read(i_file, buf, 1) == 1){ //Here should be a conditions to continue reading till EOF
.... //I need your help here
....
write(p[1], buf, c); //Here i write in the pipe the word for the parent
while(1){
pause(); //The child will wait a signal from the parent before reading the next word
break;
}
}
}else
perror("Error opening file secondo figlio");
close(fd);
close(p[1]);
}
Can you help me with this problem? Thanks in advance for the help.
EDIT: I misread the exercise, there're two different input files.