home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_09_06
/
9n06114a
< prev
next >
Wrap
Text File
|
1991-02-17
|
1KB
|
44 lines
/*
* 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;
}