C Program to Copy Content of File from Source to Destination

Question: Write a program in C to read an information of a file named "data.txt" and write its content to another file named "record.txt"

C Program to Copy Content From Source File to Destination File


#include<stdio.h>
#include<stdlib.h>

int main()
{
 FILE *source, *destination;
 char ch;
 source = fopen("data.txt","r");

 if(source==NULL)
 {
  printf("File error!");
  exit(1);
 }

 destination = fopen("record.txt","w");
 if(source==NULL)
 {
  printf("File error!");
  exit(1);
 }

 do
 {
  ch = fgetc(source);
  fputc(ch, destination);
 }while(ch!=EOF);

 fclose(source);
 fclose(destination);

 print("Program completed open record.txt to view copied content.");
 return 0;
}