帮忙编个c语言程序,应该挺简单的,谢谢

来源:百度知道 编辑:UC知道 时间:2024/06/24 16:33:06
从一个文本文件读取正文,将其中的小写字母转换成大写字母,大写字母转换成小写字母,其他字符不变,然后输出到另一个文本文件中保存.谢谢!

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

int main(void)
{
char ch;
char szfile1[255] = "c:\\1.txt";
char szfile2[255] = "c:\\2.txt";
FILE *fin, *fout;

if ((fin = fopen(szfile1, "rb")) == NULL)
{
printf("can not open file %s.");
return 1;
}

if ((fout = fopen(szfile2, "wb") == NULL)
{
fclose(fin);
printf("can not open file %s.");
return 1;
}

while ((ch = fgetc(fin)) != EOF)
{
if (ch >= 'A' && ch <= 'Z')
ch += 32;
else if (ch >= 'a' && ch <= 'z')
ch -= 32;

fputc(ch, fout);
}

fclose(fin);
fclose(fout);
return 0;
}