C ++排序对我的数据没有影响

时间:2013-03-13 22:47:19

标签: sorting fork pipe

我正在分离一个子进程,需要以反向数字顺序对几个char数组进行排序。我能够将数据传输到那里并且没有任何问题,但出于某种原因“排序”并没有对数据做任何事情。我确信我的错误很小,但我似乎无法把它搞定。有什么建议吗?

if (pid == 0){  // child process---------------------------------
    close(pipe1[1]);    // close write end of pipe1
    close(pipe2[0]);    // close read end of pipe2
    dup2(pipe1[0], STDIN_FILENO);
    dup2(pipe2[1], STDOUT_FILENO);
    close(pipe1[0]);    // close read end of pipe1
    close(pipe2[1]);    // close write end of pipe2
    execlp("sort", "sort", "-nr", NULL);    // sort incoming data
    cout << "error" << endl;    // if this line is reached, error
    exit(0);
}

0 个答案:

没有答案