Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // source code from K&R 2nd page 162
- #include <stdio.h>
- /* cat */
- int main(int argc, char *argv[])
- {
- FILE *fp;
- void filecopy(FILE *, FILE *);
- if (argc == 1)
- filecopy(stdio, stdout);
- else
- while (--argc > 0)
- if ((fp = fopen(*++argv, "r")) == NULL) {
- printf("cat: can't open %s\n", *argv);
- return 1;
- } else {
- filecopy(fp, stdout);
- fclose(fp);
- }
- return 0;
- }
- /* filecopy */
- void filecopy(FILE *ifp, FILE *ofp)
- {
- int c;
- while ((c = getc(ifp)) != EOF)
- putc(c, ofp);
- }
Add Comment
Please, Sign In to add comment