#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
int main(void)
{
FILE * fp1, * fp2;
char ch;
if((fp1 = fopen("c1.txt", "r+")) == NULL)
{
fprintf(stderr, "Can't open file c1.txt");
exit(EXIT_FAILURE);
}
if((fp1 = fopen("c2.txt", "a+")) == NULL)
{
fprintf(stderr, "Can't open file c2.txt");
exit(EXIT_FAILURE);
}
while((ch = getc(fp1)) != EOF)
{
putc(ch, fp2);
}
rewind(fp1);
while((ch = getc(fp1)) != EOF)
{
if(isalpha(ch))
ch = toupper(ch);
putc(ch, fp2);
}
if(fclose(fp1) != 0)
printf("Can't close file c1.txt");
if(fclose(fp2) != 0)
printf("Can't close file c2.txt");
return 0;
}
这个程序用来拷贝当前目录下c1.txt中的一段英文至c2.txt,并将c1.txt内容转换为大写后,紧跟着输入到c2.txt中
程序能运行也能创建c2.txt,但是c2中没有内容,如图
我的程序具体是什么问题呢,感谢大佬回答~!