Wednesday, June 15, 2022

C programming examples

 Write a program in C to copy contents from one text file to another text file

#include<stdio.h>

#include<conio.h>

#include<stdlib.h>

void main() {

   FILE *fp1, *fp2;

   char ch;

   clrscr();

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


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

   while (1) {


      ch = fgetc(fp1);

      if (ch == EOF)


         break;


      else


         putc(ch, fp2);


   }

   printf("File copied Successfully!");


   fclose(fp1);


   fclose(fp2);

}



No comments:

Post a Comment