#include #include #include #include #include /* defines for pipe use */ #define READEND 0 #define WRITEEND 1 void copy() { for (;;) { char ch; if (read( STDIN_FILENO, &ch, 1 ) == 0) break; if (ch == ' ') write( STDOUT_FILENO, "_", 1 ); write( STDOUT_FILENO, &ch, 1 ); } } main() { int mypipe[2]; pipe( mypipe ); if (fork()) { /* parent */ close( mypipe[WRITEEND] ); dup2( mypipe[READEND], STDIN_FILENO ); close( mypipe[READEND] ); copy(); (void) wait( NULL ); } else { /* child */ close( mypipe[READEND] ); dup2( mypipe[WRITEEND], STDOUT_FILENO ); close( mypipe[WRITEEND] ); copy(); exit( EXIT_SUCCESS ); } }