#include <stdio.h>
#include "stdarg.h"
//编写出将多个文件连接起来的cat程序
int main(int argc, char* argv[])
{
FILE *fp;
void filecopy(FILE *, FILE *);
if (argc == 1)
filecopy(stdin, 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;
}
//文件指针 stdin 与 stdout 都是 FILE *类型的对象。但它们是常量,而非变量。因此不能
//对它们赋值
//getc 和 putc 是宏而不是函数
void filecopy(FILE *ifp, FILE *ofp) {
int c;
while ((c = getc(ifp)) != EOF)
putc(c, ofp);
}