Write a Program to Convert the Content of File to UpperCase.
Approach 1: Using Temp File
C Program
#include <stdio.h>#include <ctype.h>int main(){FILE *fileP, *tmpP;char fileName[100];char c;printf("Enter from file name with full path: ");scanf("%s", fileName);//open file in read modefileP = fopen(fileName, "r");if (fileP == NULL){printf("Error in opening file \n");return -1;}//open file in write modetmpP = fopen("temp1.txt", "w");// first filec = getc(fileP);while (c != EOF){putc(toupper(c), tmpP);c = getc(fileP);}fclose(fileP);fclose(tmpP);//remove from fileremove(fileName);rename("temp1.txt", fileName);return 0;}
Input:
Enter from file name with full path: C:\Users\hello.txt
Input File: hello.txt
this is a c program c is a programming language Coding is Fun
Output File: hello.txt
THIS IS A C PROGRAM C IS A PROGRAMMING LANGUAGE CODING IS FUN
No comments:
Post a Comment