I'm new to C and struggling to see why this won't compile. The script should take two text files as args - read the first and copy the contents to the second. I'm getting the following error at compile:
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’
I'm not sure why it says fgetc should take more arguments because it's shown on my lecture slides taking one argument?
#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;
}