文件copy与指针数组问题,给分,很急,在线等

zouchunhui 2003-10-20 05:41:18
我的源程序如下:# include "fstream.h"
# include "iostream.h"
# include "string.h"
int open(int argc,char *argv[])
{
char ch;
//argc = 3;
//argv[1] = "c:\\a.txt";
//argv[2] = "c:\\b.txt";
//cout<<argv[1]<<" "<<argv[2]<<endl;
if(argc!=3)
{
cout<<"error,you shall use this programe as:\n\t"
<<"mycopy filename1 filename2"<<endl;
return 1;
}
ifstream myin(argv[1]);
if (!myin)
{
cout<<"cant open "<<argv[1]<<" for input"<<endl;
return 1;
}
ofstream myout(argv[2]);
if (!myout)
{
cout<<"cant open "<<argv[2]<<"for output"<<endl;
return 1;
}
while(myout&&myin.get(ch))
{
myout.put(ch);
//cout<<"sucess"<<endl;
}
myin.close();
myout.close();
return 0;
}
void main()
{
//int i=3;
char *a[100];
//for (int i=1;i<=2;i++)
//{
// a[i] = "c:\\"+str(i)+".txt";
//}
// open(i,*a[]);
a[0] = "c:\\a.txt";
a[1] = "c:\\b.txt";
int c = open(3,*a);//error
if (c==1)
{
cout<<"false"<<endl;
}
else
{
cout<<"sucess"<<endl;
}
}

//请帮忙修改一下,谢谢各位大侠了
...全文
33 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
daizh 2003-10-20
  • 打赏
  • 举报
回复
int c = open(3,*a);//error
应该改为:int c = open(3,&a[0]);

69,335

社区成员

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

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