#include<stdio.h>
#include<stat.h>
#include<fcntl.h>
main()
{
int inhandle,outhandle,bytes;
char source[128],target[128],buffer[512];
printf("enter source file name\n");
scanf("%s",source);
inhandle=open(source,O_RDONLY|O_BINARY);
if(inhandle==-1)
{
printf("cannot open source file\n");
exit(0);
}
printf("enter target file name\n");
scanf("%s",target);
outhandle=open(target,O_CREAT|O_BINARY,O_WRONLY,S_IWRITE);
if(outhandle==-1)
{
printf("cannot open target file\n");
close(outhandle);
exit(0);
}
while(1)
{
bytes=read(inhandle,buffer,512);
if(bytes>0)
{
write(outhandle,buffer,bytes);
}
else
break;
}
close(inhandle);
close(outhandle);
}
程序编译时出现 0 个错误,当我在 scanf 中传递参数时,甚至没有与打开文件相关的错误被抛出。我似乎无法使用该程序复制任何媒体文件,如 .avi 格式,该文件确实在其目标位置创建但有 0 个字节。