首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

文件复制小疑点

2013-06-26 
文件复制小问题#includestdio.h#includectype.h#includestdlib.hint main(void){FILE *file_sou,*fi

文件复制小问题

#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>

int main(void)
{
FILE *file_sou,*file_typ;
char ch,name_sou[20],name_typ[20];
printf("Please enter the source file:\n");
gets(name_sou);
printf("Please enter the copy file:\n");
gets(name_typ);

if((file_sou=fopen(name_sou,"r"))==NULL)
{
printf("Can't open the file  %s.\n",name_sou);
exit(1);
}
if((file_typ=fopen(name_typ,"r"))==NULL)
{
printf("Can't open the file %s.\n",name_typ);
exit(2);
}

while(ch=getc(file_sou))
if(toupper(ch))
putc(ch,name_typ);
fclose(file_sou);
fclose(file_typ);

return 0;
}

复制文件后,把小写字母换成大写。提示错误
D:\13章\练习3\1.cpp(27) : error C2227: left of '->_cnt' must point to class/struct/union
D:\13章\练习3\1.cpp(27) : error C2227: left of '->_ptr' must point to class/struct/union
D:\13章\练习3\1.cpp(27) : error C2664: '_flsbuf' : cannot convert parameter 2 from 'char [20]' to 'struct _iobuf *'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
执行 cl.exe 时出错.

1.obj - 1 error(s), 0 warning(s)

[解决办法]
2个问题
1,if((file_typ=fopen(name_typ,"r"))==NULL) 应该以写打开
2,   putc(ch,name_typ); 参数错了,应该用file_typ
   name_typ是文件名。

热点排行