用文件指针复制一个文件

Rookiekk 2017-03-01 07:01:38
#include<stdio.h> 
#include<stdlib.h>
#include<ctype.h>
int main(void)
{
int ch;
FILE *source,*destination;
char source_name[41],destination_name[41];
printf("input the source file's name:");
if ( (source = fopen(gets(source_name),"r")) == NULL)
{
printf ("Can't open %s\n", source_name);
exit(1);
}
printf("input the destination file's name:");
if ( (destination = fopen(gets(destination_name),"w")) == NULL)
{
printf ("Can't open %s\n", destination_name);
exit(1);
}
while ((ch = getc(source)) != EOF)
putc( toupper(ch), destination );
fclose(source);
fclose(destination);
printf ("copy finished\n");
return 0;
}

这需要把源文件放到哪啊,总是cannot open.求大神指点
...全文
93 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
幻夢之葉 2017-03-01
  • 打赏
  • 举报
回复
调试的时候在工程目录下即可 外部执行就放在当前工作目录下(默认是程序所在的目录,可以用代码修改工作目录)
自信男孩 2017-03-01
  • 打赏
  • 举报
回复
把你的编译后的可执行文件放到和你要打开的文件同一目录下即可。同时要打开的文件需要已经存在,即需要事先创建; 建议你不要是用gets,因为gets不安全。

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧