c语言为什么复制文件不成功,用dev-c++进行文件操作。怎么老是不成功啊?

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

我写的这个复制程序,只是要求提示用户输入源文件名和输出文件名,并以大写复制而已。

为什么编译成功运行后总是提示"I couldn't open the file "

而在CMD下就可以成功操作文件了。

为啥啊?

#include

#include //为了调用exit()

#include

#define len 100

int main(void)

{

FILE *in,*copy;

char ch,str1[len],str2[len];

printf("please input the name of the source file:\n");

gets(str1);

printf("please input the name of the copy file :\n");

gets(str2);

if((in=fopen(str1,"r"))==NULL) //打开源文件,得到文本流

{

fprintf(stderr,"I couldn't open the file \"%s\"\n",str1);

exit(1);

}

if((copy=fopen(str2,"w"))==NULL) //打开复制文件,以供写入

{

fprintf(stderr,"Can't create output file.\n");

exit(2);

}

while((ch=getc(in))!=EOF)

{

if(ch<='z'&&ch>='a')

ch=toupper(ch);

putc(ch,copy);

}

fclose(in); //文件操作结束后,要关闭文件!!

fclose(copy);

system("pause");

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值