/*
 *  cat.c: concatenate files.
 *      written by Leor Zolman
 *
 *  usage:
 *      cat [list of files]
 *  Sends the contents of all specified files (or the
 *  standard input, if no filenames are specified) 
 *  to the standard output.
 *  
 *  This version is intended for DOS systems only,
 *  since all *nix systems should already have it
 *  as standard equipment.
 */

#include <stdio.h>

main(int argc, char **argv)
{
    int i, c;
    FILE *fp;
    
    if (argc == 1)  /* if no filenames supplied, read input */
    {                           /* from standard input only */
        while ((i = getchar()) != EOF)
            putchar(i);
    }
    else
    {
        for (i = 1; i < argc; i++)
        {
            if ((fp = fopen(argv[i], "r")) == NULL)
            {
                fprintf(stderr, "%s: can't open %s\n",
                            argv[0], argv[i]);
                exit(1);
            }
            while ((c = getc(fp)) != EOF)
                putchar(c);
        }
    }
    return 0;
}
