Q:

How to scan the output string values run from another c program?

I am having a c program called summary.c , that will run another c program called flatfile.c , the faltfile.c after running will output and print 3 lines

the Q1 result is XX.
the Q2 result is XX.
the Q3 result is xx.

Is there any way that the summary.c after called the flatfile.c , it able to scan XX value then store as variable for the use in summary.c 
I know for the summary.c it is able to called another c program by using "execve" however, i don't know how get the result from flatfile.c and store as variable inside the summary for further calculation. 
I expect the summary.c after run it, it able to run flatfile.c and get the information it needed inside the summary.c It need to annoy "1. The Q1 result is " and also ignore "2. The Q2 result is " , get the value XX.

A:

So what we want to do is run Q1 and Q2 in a pipeline, almost as though the starting command was ./Q1 | ./Q2, but have Q1 do it. While the exec family of functions is necessary, it is not quite sufficient. Setting up the whole of the pipe is easy.
At the top of Q1:
int main()
{
    int pipefd[2];
    pid_t pid;
    pipe(&pipefd);
    if (0 == (pid = fork()) {
        close(pipefd[1]);
        dup2(pipefd[0], 0);
        close(pipefd[0]);
        execl("Q2", "Q2", ...);
        _exit(3);
    }
    dup2(pipefd[1], 1);
    close(pipefd[1]);
    close(pipefd[0]);

    /* any output with `printf()` is now input to Q2; anything with `fprintf(stderr)` still displays on screen */
}

Error handling mostly omitted for brevity. pipe(), fork(), and execl() can fail. With the first two, they return -1 for failure; if execl() returns at all you know it failed. I prefer perror() for error messages.

