关于C语言文件的题目

来源:百度知道 编辑:UC知道 时间:2024/05/19 04:16:28
1.从键盘输入一个字符串,将其中的小写字母全部转换成大写字母,然后输入到一个磁盘文件test中保存.输入的字符串以”!”结束.
2.进行文本文件的复制,即将文本文件stdio.txt的内容复制到文本文件stunew.dat中.

请完整一点.出现正确答案我马上就选为最佳.谢了!
一楼的兄弟还差一道啊..
对了..为什么第二道运行总是”Cannot open file stdio.txt”啊..

第一题:
#include"stdio.h"
#include"stdlib.h"
void main()
{
FILE *fp;
char ch;
if((fp=fopen("test.txt","w+"))==NULL)
{
printf("Cannot open file !");
exit(1);
}
ch=getchar();
while(ch!='!')
{
if(ch>=97)
ch-=32;
fprintf(fp,"%c",ch);
ch=getchar();
}
fclose(fp);
}

第二题:
#include"stdio.h"
#include"stdlib.h"
void main()
{
FILE *fp,*fp2;
char ch[100];
if((fp=fopen("stdio.txt","r"))==NULL)
{
printf("Cannot open file stdio.txt!");
exit(1);
}
if((fp2=fopen("stunew.dat","w+"))==NULL)
{
printf("Cannot open file stunew.dat!");
exit(1);
}
while(!feof(fp))
{
fgets(ch,100,fp);
fputs(ch,fp2);
}