home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 351.lha / cat / cat.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-02-25  |  1.0 KB  |  52 lines

  1.  
  2. /* cat - amiga program to concatenate files, requires ANSI C */
  3.  
  4. /* Released to the public domain by Karl Lehenbauer, 1-Feb-1990 */
  5.  
  6. #include <stdio.h>
  7. #include <fcntl.h>
  8.  
  9. void catfile(const char *fname)
  10. {
  11.        FILE *fp;
  12.        char s[1024];
  13.  
  14.        if ((fp = fopen(fname,"r")) == NULL)
  15.        {
  16.                perror(fname);
  17.                return;
  18.        }
  19.  
  20.        while (fgets(s, sizeof(s), fp) != NULL)
  21.                fputs(s, stdout);
  22.  
  23.        if (ferror(fp))
  24.                fprintf(stderr,"cat: error occured reading %s\n",fname);
  25.  
  26.        fclose(fp);
  27. }
  28.  
  29. main(int argc, char *argv[])
  30. {
  31.        char *fname;
  32.        int i;
  33.  
  34.        if (argc < 2)
  35.        {
  36.                fprintf(stderr,"usage: cat [>outfile] file [file..]\n");
  37.                exit(1);
  38.        }
  39.  
  40.        for (i = 1; i < argc; i++)
  41.                while ((fname = scdir(argv[i])) != NULL)
  42.                        catfile(fname);
  43.  
  44.        if (ferror(stdout))
  45.        {
  46.                fprintf(stderr,"cat: error occured while writing output file\n");
  47.                exit(2);
  48.        }
  49.  
  50.        exit(0);
  51. }
  52.