Copy file & change lower case to upper case - C

Write a C program to copy one file to another file & while doing so replace all lower case character to their equivalent upper case character.

Solution:

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int main()
{
      FILE *fp1, *fp2;
      char ch;
      fp1 = fopen("source.txt", "r");
      if (fp1 == NULL)
      {
            puts("File does not exist..");
            exit(1);
      }
      fp2 = fopen("target.txt", "w");
      if (fp2 == NULL)
      {
            puts("File does not exist..");
            fclose(fp1);
            exit(1);
      }
      while((ch=fgetc(fp1))!=EOF)
      {
            ch = toupper(ch);
            fputc(ch,fp2);
      }
      printf("\nFile successfully copied..");
      return 0;
}


Output:

lower to upper

Content in source.txt file.

source

All the lower-case letters in source.txt are converted into their upper case form in following target.txt file.

result file