我是 C 的新手,很难理解为什么它不能编译。该脚本应采用两个文本文件作为参数 - 读取第一个并将内容复制到第二个。我在编译时收到以下错误:
root@debian:/home/kevin# gcc -Wall mycat.c -o mycat
mycat.c: In function ‘main’:
mycat.c:4:3: error: too few arguments to function ‘fgetc’
In file included from mycat.c:1:0:
/usr/include/stdio.h:533:12: note: declared here
mycat.c:5:5: error: too few arguments to function ‘fputc’
我不确定为什么它说 fgetc 应该接受更多参数,因为它显示在我的演讲幻灯片上接受一个参数?
#include <stdio.h>
#include <stdlib.h>
int main(){
const char∗ ifilename = $1;
FILE∗ istream = fopen(ifilename, ”r”);
if (istream == NULL) {
fprintf(stderr, ”Cannot open %s \n”,ifilename);
exit(1);
}
const char∗ ofilename = ”$2”;
FILE∗ ostream = fopen(ofilename, ”w”);
if (ostream == NULL) {
fprintf(stderr, ”Cannot open %s \n” , ofilename);
exit(1);
}
int = c;
while ((c = fgetc(istream)) != EOF)
fputc(ostream);
return 0;
}