/* 8.5 从键盘输入一行字符,将其中小写字母转换为大写字母 */
#include "stdio.h"
void main()
{
FILE *fp;
char ch;
if((fp=fopen("c:\\ex85.txt","w"))==NULL)
{
printf("不能创建文件c:\\ex85.txt");
exit(1);
}
printf("请输入一行字符\n");
while((ch=getchar())!='\n')
{
if(ch>='a' && ch<='z')
ch=ch-32;
fputc(ch,fp);
}
fclose(fp);
printf("操作成功");
}
/* 8.7 把一个ASCII文件连接在另外一个ASCII文件之后。 把c:\\ex87_1.txt中的字符连接在c:\\ex87_2.txt中的之后*/
#include "stdio.h"
void main()
{
FILE *fp1,*fp2;
char ch;
if((fp1=fopen("c:\\ex87_1.txt","r"))==NULL)
{
printf("不能打开文件c:\\ex87_1.txt");
exit(1);
}
if((fp2=fopen("c:\\ex87_2.txt","a"))==NULL)
{
printf("不能打开文件c:\\ex87_2.txt");
exit(1);
}
while((ch=fgetc(fp1))!=EOF)
{
fputc(ch,fp2);
}
fclose(fp1);
fclose(fp2);
printf("操作成功,请打开c:\\ex87_2.txt查看结果");
}
标签:练习题,fp,ch,ex85,字符,C语言,printf,txt,参考答案
From: https://blog.51cto.com/emanlee/8246696