Thursday, September 13, 2012

Convert File Contents To Uppercase In C

Compiler Used: TurboC
Language: C

This program copies content from a.txt converts it into uppercase and writes it to file b.txt.


#include<stdio.h>
#include<conio.h>

void main(){
clrscr();
char c;
FILE *fp1, *fp2;
fp1 = fopen("a.txt", "r");
fp2 = fopen("b.txt", "w");
while((c = getc(fp1))!=EOF){
//printf("%c", c);
//getch();
if(c>=97){
 c = c-32;
}
putc(c, fp2);
}
fclose(fp1);
fclose(fp2);
fp2 = fopen("b.txt", "r");
while((c=getc(fp2))!=EOF){
 putchar(c);
}
fclose(fp2);
getch();
}

PS: Comments/Suggestions/Improvements are welcome.

No comments:

Post a Comment