I am trying to copy the contents from one file to another in c using the terminal on my mac.
I keep receiving this error when I try to compile the code, and I am unsure as to why.
This is my code:
#include <stdio.h>
#include <stdarg.h>
int main(int argc, char *argv[])
{
FILE *f1Ptr, *f2Ptr;
char x;
if(argc != 3)
{
printf("Incorrect number of arguments\n");
}
f1Ptr = fopen(argv[1], "r");
f2Ptr = fopen(argv[2], "w");
if(f1Ptr == NULL || f2Ptr == NULL)
{
puts("File could not be opened");
}
while(!feof(f1Ptr))
{
x = fgetc(f1Ptr);
fputc(x, f2Ptr);
}
printf("File has been copied\n");
fclose(f1Ptr);
fclose(f2Ptr);
return 0;
}
This is the error
ld: file too small (length=0) file 'file2.txt' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Build command: "gcc q2.c file1.txt file2.txt ld: file too small (length=0) file 'file2.txt' for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)