Question: So I have this homework question: In Section 2.3, we described a program that copies the contents of one file to a destination file. This

So I have this homework question:

In Section 2.3, we described a program that copies the contents of one file to a destination file. This program works by first prompting the user for the name of the source and destination files. Write this program using either the Win32 or POSIX API. Be sure to include all necessary error checking, including ensuring that the source file exists. Once you have correctly designed and tested the program, if you used a system that supports it, run the program using a utility that traces system calls. Linux systems provide the ptrace utility, and Solaris systems use the truss or dtrace command. On Mac OS X, the ktrace facility provides similar functionality. As Windows systems do not provide such features, you will have to trace through the Win32 version of this program using a debugger.

I already wrote a c program that reads and write the file but I don't know what POSIX API is or how to us ptrace. I'm using ubuntu.

// CS 474 // Program Name: homework1.c // Author: Melissa Duran // Date: 10/5/2017 // Purpose: Reads and copies what is written in one file to another

#include #include #include FILE *cfPtr1; FILE *cfPtr2; char whatIWrite;

int main (void) { char *fileToRead = malloc(101); char *fileToWrite = malloc(101); printf("Please enter the name of the file to be read: "); scanf("%s",fileToRead); //if file is read as empty retruns teh text File could not be opened if ( (cfPtr1 = fopen(fileToRead, "r" )) == NULL) { puts( "File could not be opened "); } printf("Please enter the name of the file where you would like to write: "); scanf("%s", fileToWrite); //if file is read as empty retruns teh text File could not be opened if ( (cfPtr2 = fopen(fileToWrite, "w" )) == NULL) { puts( "File could not be opened "); } //Everything is well and we can copy the files. else{ //Read from fileToRead whatIWrite = fgetc(cfPtr1); while (whatIWrite != EOF){ fputc(whatIWrite, cfPtr2); whatIWrite = fgetc(cfPtr1); } printf("The file has been copied."); //closes the file fclose ( cfPtr1 ); fclose ( cfPtr2 ); }//End else return 0; } // end main

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!