Write a program in C to read the contents of a file, convert them into uppercase and copy to another file using file handling.

Convert File Content to Uppercase and Copy to Another File
This program reads the contents of a file, converts each character into uppercase, and writes the result into another file.
The logic is simple:
• Open source file in read mode
• Open destination file in write mode
• Read each character from source file
• Convert it to uppercase using toupper()
• Write it into destination file
Program
#include <stdio.h>
#include <ctype.h>
int main() {
FILE fp1, fp2;
char ch;
fp1 = fopen("input.txt", "r");
fp2 = fopen("output.txt", "w");
if(fp1 == NULL || fp2 == NULL) {
printf("Error opening file");
return 0;
}
while((ch = fgetc(fp1)) != EOF) {
ch = toupper(ch);
fputc(ch, fp2);
}
fclose(fp1);
fclose(fp2);
printf("Data copied in uppercase successfully");
return 0;
}
Important Points
• toupper() is used to convert lowercase to uppercase
• Always check if file opened successfully
• EOF means End Of File
• Use fgetc() to read and fputc() to write
Output Example
Input file: hello world
Output file: HELLO WORLD
Final Tip
This is a very common exam question. Focus on logic, not just code memorization.

Written by
Palak PatelEducation writer Palak Patel covers the latest education news, board exam updates, results, and career opportunities.
