I'm trying to write a program that will implement command:

```
ls -al | tr 'a-z' 'A-Z' | grep X > testing

```

Basically I want to learn how to use piping twice in C. There is a lot of post where we're using only one '|'. I made some attempts based on examples with only one '|' but sadly it doesn't work. There is a code.

```
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#define MAX 512
int main(int argc,char** argv){
    int pdesk[2];
    int pipedesk[2];
    if(pipe(pipedesk)==-1 || pipe(pdesk)==-1){
        perror("Pipe");
        exit(1);
    }
    switch(fork()){
        case -1 :
                perror("Creating process");
                exit(1);
        case 0:
                dup2(pdesk[1],STDOUT_FILENO);
                close(pdesk[1]);
                execlp("ls","ls","-al",NULL);
                perror("ls");
                exit(1);
        default: {
                if(fork()==0){
                    if(fork()==0){
                        dup2(pdesk[0],STDIN_FILENO);
                        close(pdesk[0]);
                        dup2(pipedesk[1],STDOUT_FILENO);
                        close(pipedesk[1]);
                        execlp("tr","tr","a-z","A-Z",NULL);
                        perror("tr");
                        exit(1);
                    }
                    dup2(pipedesk[0],STDIN_FILENO);
                    close(pipedesk[0]);
                    int desk=open("testing",O_WRONLY|O_CREAT,0640);
                    if(desk==-1){
                        perror("opening file");
                        exit(1);
                    }
                    dup2(desk,STDOUT_FILENO);
                    if(close(desk)==-1){
                        perror("closing file");
                        exit(1);
                    }
                    execlp("grep","grep","X",NULL);
                    perror("grep");
                    exit(1);
                }
//              wait(NULL);

        }
        return 0;
    }
}

```