Question: [In C] Write a copy program similar to cp in Bash. An execution of your program will take two command-line arguments. It should then try
[In C]
Write a copy program similar to cp in Bash. An execution of your program will take two command-line arguments. It should then try to open the file named by the first command-line argument. If successful, it should try to create a file with the name given in the second command-line argument, but without clobbering (deleting) any existing file by that name. If again successful, it should loop through the contents of the first file, writing them to the second file. Finally, it should close both files and print out the total number of bytes copied. Be sure to check for any errors in opening, creating, reading and writing the files, and print an appropriate error message if one is encountered. An execution of your program should look like this:
~$ ./mycp file1 file2 copied 512 bytes
Your code should use a buffer with size of 1024 bytes. You should use the low level file I/O API for reading/writing the files (i.e., open(), close(), read() and write()). This API is also referred to as the OPEN family of Linux system calls. Use the printf() for writing the number of bytes copied.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
