Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Homework Assignment #2. Basic Programming Skills Review Section 2.3 (Figure 2.4) of our textbook describes an algorithm for implementing a COPY program. This program prompts

Homework Assignment #2. Basic Programming Skills Review

Section 2.3 (Figure 2.4) of our textbook describes an algorithm for implementing a COPY program. 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 programs user interface should appear exactly as follows:

Welcome to the File Copy Program by !

Enter the name of the file to copy from:

Enter the name of the file to copy to:

File Copy Successful, 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 27 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). 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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB.NET Databases

Authors: Thearon Willis

1st Edition

1594864217, 978-1594864216

More Books

Students also viewed these Databases questions