Problems with pipe IPC

I'm currently studying IPC, I have a first program

A: Do an exec for B and wait

B: Receive through a fifo a string from a third program "C" and have to resend it to A

I was thinking to open a pipe in A before the exec, then passing fd[1] to B as an argument

    if(pipe(fd)==-1){
        perror("Pipe Failed");
        myExit(EXIT_FAILURE);
    }

    close(fd[1]);    
    sprintf(fdString,"%d",fd[1]);

        .......

    if((int)(pid=fork())>0)
        
        waiting(status);    
    
    else if(pid==0){    
        
        close(fd[0]);    

        execl("./B","B",fdString,(char*)0);
        perror("Exec failed");
        myExit(EXIT_FAILURE);

    }

Then in B:

    int fd=atoi(argv[1]);
        
        //Receive string from C 

           len=strlen(string)+1;

    if(write(fd,&len,sizeof(int))==-1){
        perror("Error on writing length");
        exit(EXIT_FAILURE);    
    }

    if(write(fd,&string,len)==-1){
        perror("Error on writing string");
        exit(EXIT_FAILURE);        
    }

My problem now is reading this string in A. I was thinking to send a SIGUSR1 to A as soon as the string is written by B on the pipe and having in A something like:

    signal(SIGUSR1, signalHandler);
        ........
          static void signalHandler(int signo){
        switch(signo){
        case SIGUSR1:
            listen();
            break;
        default: break;

        }
    }
        ........
    static void listen(){
    
        int len;
    
        if(read(fd[0],&len,sizeof(int))<sizeof(int)){
            perror("Error reading len");
            myExit(EXIT_FAILURE);    
        }
    
        char string[len];
    
        if(read(fd[0],string,len)<len){
            perror("Error reading string");
            myExit(EXIT_FAILURE);    
        }
        printf("String: %s with length %d\n", string, len);
    }

However what I get is "Error reading len: Success" , what's wrong ?

Sorry if my English is bad, any help is appreciated, thanks!

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.