I think your pipe is set up correctly. The problems may start at execl()
. For this call you should specify an absolute path, which is probably /bin/sort
if you mean the Unix utility. There is also a version of the call execlp()
which searches automatically on the PATH.
The next problem is that sort
is text based, more specifically line based, and you're sending binary garbage to its STDIN.
In the parent process you should write formatted text into the pipe.
FILE *wpipe = fdopen(fd[1], "w");
for (i = 100; i < 110; i++) {
fprintf(wpipe, "%d\n", i);
...
}
fclose(wpipe);
A reverse loop from 110 down to 100 may test your sorting a bit better.