Question: I have course assignment, the problem is taken from Operating System Concept 9th by Abraham Silberchatz, Programming Problems 2.26 (page 92): In Section 2.3 of
I have course assignment, the problem is taken from Operating System Concept 9th by Abraham Silberchatz, Programming Problems 2.26 (page 92):
In Section 2.3 of CHAPTER 2, 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 Windows 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 strace utility, and Solaris and Mac OS X systems use the dtrace command. As Windows systems do not provide such features, you will have to trace through the Windows version of this program using a debugger.
The instructor asked me to :
1. write the code ==> Already answered (I already have the code.)
2. show the tracing result
3. explain the result
So, I need help for point 2 & 3 only. Number 1 is already solved. Thanks. (I am new to C, have no experience in running C program)
The code is as follows:
#include
printf("Enter the filename to open for reading "); scanf("%s", filename); 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);
fptr2 = fopen(filename, "w"); if (fptr2 == NULL) { printf("Cannot open file %s ", filename); exit(0); } c = fgetc(fptr1); while (c != EOF) { fputc(c, fptr2); c = fgetc(fptr1); }
printf(" Contents copied to %s", filename);
fclose(fptr1); fclose(fptr2); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
