C Program File Handling

Ram Pothuraju

This is a C Programs which copies the content of one file to other (file1.txt to file2.txt). 



#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
  FILE *in, *out;
  char ch;
  int flag;
  clrscr();
  if ((in = fopen("C:\\hello\\file1.txt", "rt"))
    == NULL)
  {
   printf("Cannot open input file.\n");
   getch();
   return;
  }

  if ((out = fopen("C:\\hello\\file2.txt", "wt"))
    == NULL)
  {
   printf("Cannot open output file.\n");
   getch();
   return;
  }


  while (!feof(in))
   {
   flag=1;
   ch=fgetc(in);
   ch=toupper(ch);
   fputc(ch, out);
   }
  fclose(in);
  fclose(out);
  if (flag==1)
  {
  printf("The File copy is complete\n");
  }
  getch();
}

Tags

Post a Comment

0Comments

Post a Comment (0)