Reading and multiple operations with text file in C || File handling || C programming
In this, we are going to see a program in which we will read a text file and convert the file contents in Uppercase and write the contents in a output file in C Programming Language.

//Program to read a text file and convert the file contents in Uppercase and write the contents in a output file

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

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

    fp1 = fopen("d:\\Program test.txt", "r");

    if (fp1 == NULL)
    {
        puts("cannot open this file");
        exit(1);
    }

    fp2 = fopen("d:\\Program test1.txt", "w");
    if (fp2 == NULL)
    {
        puts("Not able 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);
}

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post