C program to copy content of file into another file with uppercase

C program to copy content of file into another file with uppercase:
If you are using any software then below program will not give an error, but if you are using TURBO C then you have to make some changes like: void main() and some function like clrscr() or getch().



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

main()
{
   FILE *fp1,*fp2;
   char a;

   fp1=fopen("readingfile.txt","r"); // Accepting filename for reading
   if (fp1 == NULL)
    {
      puts("cannot open file");
      exit(1);
    }

   fp2=fopen("towrite.txt","w"); // Accepting filename for writing
   if (fp2 == NULL)
    {
      puts("Unable to open this file");
      fclose(fp1);
      exit(1);
    }

   do
    {
      a=fgetc(fp1);
      a=toupper(a);
      fputc(a,fp2);
    }while(a != EOF);

   fclose(fp1);
   fclose(fp2);
}

 

Leave a Reply

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

four × two =