QuestionQuestion

This program prompts the user for the input and output file names, then copies the contents of the input file to the output file. You will be implementing this pseudocode. The standard tee command copies data from standard input to standard output (like an ordinary shell pipe), however it also writes a copy of standard input to a file named on the command line. See the man page for details. Your program’s user interface should appear exactly asfollows:

Welcome to the File Copy Program by <yourname>! Enter the name of the file to copy from:
<type in file name & hit return> Enter the name of the file to copy to:
<type in the file name & hit return>
File Copy Successful, <number> bytes copied

You will implement this program in the C language (gcc compiler) using the POSIX (i.e. Linux) API/gcc compiler. Your code should use a buffer of size 13 bytes.
Following the pseudocode logic, the file read will repeatedly read from the input file into the buffer, and the file write will repeatedly write from the buffer to the output file.

For the Linux implementation, use the low-level file I/O API for reading/writing the files (this API is also referred to as the OPEN family of Linux system calls); use the FORMATTED I/O API for prompting the user and reading user input (this API is also referred to as the FOPEN family of system calls). DO NOT USE THE FOPEN family calls for reading and writing to and from files. Be sure to include all necessary error checking, including ensuring that the source file exists and the destination file does not exist (before opening it). Use the man page entries for function prototypes, details on how to use each system call as well as all of the necessary #include files. Note that most system calls are in section 2 or 3 of the man pages (i.e. use ‘man 2 write’ not ‘man write’ to get information about the write system call).

1. Implement your program and test it for correct implementation using three (small) test files. Use the Linux diff utility to compare your input and output files. Also instrument your program with debugging code to display the buffer contents during each file read/write iteration. Include debugging output for a small test file; and also test your program using 3 larger files (without debugging output). Once you have correctly designed and tested your program, run the program using the strace utility that traces (lists) all of the system calls used during execution. Explain (annotate) this output. Do your best to explain this output. This explanation should be writing in your readme.txt file. Set the strace flags to display the number of times each syscall is used in your program.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
//You may also add more include directives as well.

//THIS VALUE CANNOT BE CHANGED.
//You should use this value when creating your buffer.
// And also to limit the amount each read CAN do.
#define BUFF_MAX 13

int main(int argc, char const *argv[]) {

    char name[20] = "My name";
    char from[512];
    char to[512];
   
    printf("Welcome to the File Copy Program by %s!\n", name);...

By purchasing this solution you'll be able to access the following files:
Solution.c.

$50.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats