Advertisement
Guest User

propre

a guest
Mar 29th, 2015
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. int fds[2];
  2.     pipe(fds);
  3.    
  4.     if(fork()==0){
  5.         int n;
  6.         char buff[MAX];
  7.         close(fds[0]);
  8.         while((n=read(0,buff,MAX))){
  9.             int i;
  10.             for(i=0;i<n;i++){
  11.                 buff[i]=tolower(buff[i]);
  12.             }
  13.             write(fds[1],buff,n);
  14.         }
  15.     }
  16.     else{
  17.         int m;
  18.         char buff2[MAX];
  19.         close(fds[1]);
  20.         while((m=read(fds[0],buff2,MAX))){
  21.             int j;
  22.             int cmp=0;
  23.             char tmp[m];
  24.             for(j=0;j<m;j++){
  25.                 if(j>0){
  26.                     if(tmp[cmp]!=buff2[j]){
  27.                         cmp++;
  28.                         tmp[cmp]=buff2[j];
  29.                     }
  30.                 }
  31.                 else{
  32.                     tmp[j]=buff2[j];
  33.                 }
  34.             }
  35.             write(1,tmp,cmp+1);
  36.         }
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement