home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 10
/
Fresh_Fish_10_2352.bin
/
useful
/
util
/
edit
/
mg
/
src.lzh
/
tools
/
cat.c
next >
Wrap
C/C++ Source or Header
|
1990-05-23
|
604b
|
38 lines
/* (This program is from p. 154 of the Kernighan and Ritchie text */
#include <stdio.h>
#include <stdlib.h>
void
filecopy(FILE *fp) /* copy file fp to standard output */
{
int c;
while ((c = getc(fp)) != EOF)
putc(c, stdout);
}
void
main(int argc, char **argv) /* cat: concatenate files */
{
FILE *fp;
if (argc == 1) /* no args; copy standard input */
filecopy(stdin);
else
while (--argc > 0)
if ((fp = fopen(*++argv, "r")) == NULL) {
fprintf(stderr,
"cat: can't open %s\n", *argv);
exit(1);
} else {
filecopy(fp);
fclose(fp);
}
exit(0);
}