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

This is a system level program to be written in C language. It is required to in

ID: 640295 • Letter: T

Question

This is a system level program to be written in C language. It is required to include all necessary error checking. It is a file copy program. The structure should be as follows;

Accept source file name and destination file name from command line

if source file does not exists

display error message

exit

else if it is not readable

display error message

exit

open the source file

if failed to open the source file

display error message

exit

open the destination file

If the destination file exists

prompt the user whether to overwrite the destination file

if user enters no

prompt user whether to append to the destination file

if user enters no

display a message

exit

else

open the destination for append

else

open the destination file for overwrite

else

read the source file status using stat system call

create the destination file using the same st_mode as the source file

copy file

close both files.

Explanation / Answer

#include<stdio.h>

#include<process.h>

void main() {

   FILE *fp1, *fp2;

   char a;

   clrscr();

   fp1 = fopen("test.txt", "r");

   if (fp1 == NULL) {

      puts("cannot open this file");

      exit(1);

   }

   fp2 = fopen("test1.txt", "w");

   if (fp2 == NULL) {

      puts("Not able to open this file");

      fclose(fp1);

      exit(1);

   }

   do {

      a = fgetc(fp1);

      fputc(a, fp2);

   } while (a != EOF);

   fcloseall();

   getch();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote