[Solved] C program with functionality as cp command

The open() system call returns a file descriptor, which may not be 1, so your termination condition, while(infile==1){ is compeletely bogus. You should test if the read() call read any input (the return value is the number of bytes read, which is zero when it hit end-of-file.) Please read the read man page… pun intended … Read more