Answer to Question #210241 in C for Pragadeesh

Question #210241

Develop a C program to copy the content of one file and store that content in another file


1
Expert's answer
2021-06-24T03:35:26-0400
#include <stdio.h>
#include <stdlib.h> 




int main() {


	FILE *sourceFilePtr, *targetFilePtr;
	char sourceFile[20];
	char targetFile[20];
	char letter;


	printf("Enter source file: ");
	gets(sourceFile);
	sourceFilePtr = fopen(sourceFile, "r");
	if (sourceFilePtr != NULL) {
		printf("Enter target file: ");
		gets(targetFile);
		targetFilePtr = fopen(targetFile, "w");
		while ((letter = fgetc(sourceFilePtr)) != EOF){
			fputc(letter, targetFilePtr);
		}
		printf("File copied successfully.\n");
		fclose(sourceFilePtr);
		fclose(targetFilePtr);
	}else{
		printf("The file %s does not exist.\n",sourceFile);
	}




	getchar();
	getchar();
	return 0;
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS