Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please label each step of the program. \"we are not using the Solaris systems to

ID: 3889321 • Letter: P

Question


please label each step of the program.
"we are not using the Solaris systems to trace system calls with this project".

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.

Explanation / Answer

#include #include // For exit() int main() { FILE *fptr1, *fptr2; char filename[100], c; printf("Enter the filename to open for reading "); scanf("%s", filename); // Open one file for reading fptr1 = fopen(filename, "r"); if (fptr1 == NULL) { printf("Cannot open file %s ", filename); exit(0); } printf("Enter the filename to open for writing "); scanf("%s", filename); // Open another file for writing fptr2 = fopen(filename, "w"); if (fptr2 == NULL) { printf("Cannot open file %s ", filename); exit(0); } // Read contents from file c = fgetc(fptr1); while (c != EOF) { fputc(c, fptr2); c = fgetc(fptr1); } printf(" Contents copied to %s", filename); fclose(fptr1); fclose(fptr2); return 0; }