c - Linux pipes communication -


i have following program

#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]);  } 

} reads file , sends characters first children , children extracts uppercase letters , sends them second children. works fine if send characters when want send uppercase write functions return -1. question why happening?


Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -