我有以下程序
#include<stdio.h>
FILE *f;
int main()
{
int pfd[2];
int pfd1[2];
int pfd2[2];
int pid1;
int pid2;
pipe(pfd);
pipe(pfd1);
if(pfd<0||pfd1<0)
{
printf("Eroare la crearea pipe-ului\n");
exit(1);
}
f=fopen("date","r");
pid1=fork();
if(pid1==0){
close(pfd[1]);
close(pfd1[0]);
char c;
int rd;
while((rd=read(pfd[0],&c,1))>0){
printf("%c",c);
if(c>='A'&&c<='Z') {printf(" mare ");printf("%d:",write(pfd[1],&c,1));}
}
close(pfd1[1]);
close(pfd[0]);
exit(0);
}
pid2=fork();
if(pid2==0){
close(pfd1[1]);
close(pfd[0]);
close(pfd[1]);
char c;
int rd=read(pfd1[0],&c,1);
while((rd=read(pfd1[0],&c,1))>0){
printf("-2-%c",c);
}
close(pfd1[0]);
exit(0);
}
if(pid1>0&&pid2>0){
close(pfd[0]);
close(pfd1[1]);
close(pfd1[0]);
while(!feof(f)){
char c;
fscanf(f,"%c",&c);
if(feof(f)) break;
write(pfd[1],&c,1);
}
close(pfd[1]);
}
} 它的作用是从文件中读取然后将字符发送给第一个子节点,并且子节点提取大写字母并将它们发送给第二个子节点。如果我发送所有字符但是当我只想发送大写写函数返回-1时,一切正常。我的问题是为什么会这样?