I have an assignment where i have to write a custom file copy program for UNIX. We are not allowed to use system() and cannon use the UNIX cp command in any way.
command line looks like this:
mycp orig dest
orig is copied to dest.
If dest does not exist, it is created. If it does exist, it is overwritten. If dest is a directory, orig is copied into that directory with the same file name, ie. c:\orig -> c:\dest\orig
Now the problem:
this code is simplified a lot
If dest exists, the file copies fine. But if dest doesn't exist, the file pointer is 0 and I get a segmentation fault when it tries to write to it.
FILE *src, *dst;
src = fopen(argv,"rb");
dst = fopen(argv, "wb");
while(fgets(data,sizeof(data),src) != NULL)
Also, how do I check if dest is a directory?
Any help would be appreciated. Thanks