Wednesday, November 11, 2009

Chap12[C]e Lowercase to uppercase in file

Write a program to copy one file to another. While doing so replace all lowercase characters to their equivalent uppercase characters.

#include "stdio.h"

void main()
{
FILE *fp,*ft;
char ch;

fp=fopen("c:\\ctxt\\txt1.txt","r");
ft=fopen("c:\\ctxt\\txt2.txt","w");

if(fp==NULL)
{
puts("Cannot open file");
exit();
}

if(ft==NULL)
{
puts("Cannot open file");
exit();
}

while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
if(ch>=97&&ch<=122)
ch-=32;
fputc(ch,ft);
}

fclose(fp);
fclose(ft);
}

No comments:

Post a Comment