Here is a quick modification of the first pipe example in "Unix Nextwork Programming" by W. Richard Stevens, to handle arrays. His example is just a quick demonstration of pipes. I modified it quickly and crudely to work with an array, with a slight variation on his error logging, to use standard prinf instead.
Code:
#include <stdio.h>
#include <stdlib.h>
int main( void )
{
int pipefdarray[3][2], n,p;
char buff[3][100];
for( n = 0; n < 3; n++ )
if( pipe( pipefdarray[n] ) < 0 )
{
printf( "Error calling pipe on %d.\n", n );
exit( EXIT_FAILURE );
}
for( n = 0; n < 3; n++ )
printf("read fd[%d] = %d, write fd[%d] = %d\n",
n, pipefdarray[n][0], n, pipefdarray[n][1] );
for( n = 0; n < 3; n++ )
if( write( pipefdarray[n][1], "hello world\n", 12 ) != 12 )
printf( "Error writing on pipe %d\n", pipefdarray[n][1] );
for( n = 0; n < 3; n++ )
if( (p=read( pipefdarray[n][0], buff[n], sizeof( buff[n] ) ) ) <= 0 )
printf( "Error reading on pipe %d\n", pipefdarray[n][0] );
for( n = 0; n < 3; n++ )
write( 1, buff[n], p );
return 0;
}
Quick copy/paste from vi, so the formatting may not be to your liking. However, it demonstrates an array of pipes, which is what you were looking for. Very simple really.
On an aside, I would highly recommend the book I mentioned.
Quzah.