Write a C program which copies one file to another, replacing all lowercase characters with their uppercase equivalents.
Write a C program which copies one file to another, replacing all lowercase characters with their uppercase equivalents.
file1.txt
Welcome to StudyGlance
C Program
//copies one file to another, replacing all lowercase characters with their uppercase equivalents.
#include <stdio.h>
#include <ctype.h>
int main() {
FILE *src, *dest;
char ch;
// Open source file
src = fopen("file1.txt", "r");
if (src == NULL) {
printf("Error: Cannot open source file.\n");
return 1;
}
// Open destination file
dest = fopen("file2.txt", "w");
if (dest == NULL) {
printf("Error: Cannot create destination file.\n");
fclose(src);
return 1;
}
// Copy characters with conversion
while ((ch = fgetc(src)) != EOF) {
fputc(toupper(ch), dest);
}
printf("File copied successfully with uppercase conversion.\n");
// Close files
fclose(src);
fclose(dest);
return 0;
}
OUTPUT
File copied successfully with uppercase conversion.
file2.txt
WELCOME TO STUDYGLANCE
๐ป Run This C Program
Write a C program which copies one file to another, replacing all lowercase characters with their uppercase equivalents.
The selected C program is loaded automatically. Edit the code,
provide input through STDIN and click Run.
The compiler is embedded using OneCompiler. Your program runs in
the embedded C environment; Study Glance does not execute C code
directly on your web server.