C PROGRAMMING

write a c program to copy contents of one file to another file

C program to copy contents of one file to another file?

#include<stdio.h>
#include<string.h>

main() {
FILE *fp1, *fp2;
char a;
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);
fclose(fp1);
fclose(fp2);
getch();
}

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button