Back to index

texmacs  1.0.7.15
pnambic.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <unistd.h>
00003 
00004 int main(int argc, char **argv)
00005 { FILE *in,*out; int c1,c2;
00006   if (argc!=3) { fprintf(stderr,"usage: pnambic infile outfile\n"); exit(1); }
00007   in=fopen(argv[1],"r");
00008   if (!in) { fprintf(stderr,"cannot read from %s\n",argv[1]); exit(1); }
00009   out=fopen(argv[2],"w");
00010   if (!out) { fprintf(stderr,"cannot write to %s\n",argv[2]); exit(1); }
00011   if (fork())
00012   { fclose(out); fclose(stdin);
00013     while (1)
00014     { c1=fgetc(in);
00015       if (c1==EOF) break;
00016       fputc(c1,stdout); fflush(stdout);
00017     }
00018     fclose(in); fclose(stdout); exit(0);
00019   }
00020   else
00021   { fclose(in); fclose(stdout);
00022     while (1)
00023     { c2=fgetc(stdin);
00024       if (c2==EOF) break;
00025       fputc(c2,out); fflush(out);
00026     }
00027     fclose(out); fclose(stdin); exit(0);
00028   }
00029 }