home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 154_01 / cat.c < prev    next >
Text File  |  1979-12-31  |  768b  |  43 lines

  1. /* cat.c:    concatenate files */
  2.  
  3. /*    Practically copied right out of Kernighan/Ritchie by
  4.     Chuck Allison for Mark Williams C - 1985
  5. */
  6.  
  7. #include <stdio.h>
  8. #define MAXFILES 150
  9.  
  10. main(argc,argv)
  11. int argc;
  12. char *argv[];
  13. {
  14.     FILE *fp;
  15.     int maxarg = MAXFILES, xargc, i;
  16.     char *xargv[MAXFILES];
  17.  
  18.     if (argc == 1)
  19.         filecopy(stdin);
  20.     else {
  21.         /* ..expand filespecs (Mark Williams C only!).. */
  22.         xargc = exargs("files",argc,argv,xargv,maxarg);
  23.  
  24.         for (i = 0; i < xargc; ++i)
  25.             if ((fp = fopen(xargv[i],"r")) == NULL) {
  26.                 printf("can't open: %s\n",xargv[i]);
  27.                 exit(1);
  28.             } else {
  29.                 filecopy(fp);
  30.                 fclose(fp);
  31.             }
  32.     }
  33. }
  34.  
  35. filecopy(fp)
  36. FILE *fp;
  37. {
  38.     int c;
  39.  
  40.     while ((c = getc(fp)) != EOF)
  41.         putc(c,stdout);
  42. }
  43.