将一个文件里的大写字母转化成小写的,小写的变成大写的。为什么写不了呢?
#include <stdio.h>#include <stdlib.h>
int main()
{
FILE *fp;
char ch;
fp=fopen("D:\\filename.txt","r+");
if(fp==NULL)
{
printf("Can't open the file!\n");
exit(0);
}
while((ch=fgetc(fp))!=EOF)
{
if(ch>='a'&&ch<='z')
{
ch=ch-('a'-'A');
}
else if(ch>='A'&&ch<='Z')
{
ch=ch+('a'-'A');
}
fputc(ch,fp);
}
fclose(fp);
return 0;
}