0
#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);
}
程序,没有错误编译,当我传递参数在scanf甚至有没有涉及到打开该文件的错误时似乎thrown.i不能复制任何媒体文件就像.avi格式一样,该文件在其目标位置创建,但是只有0个字节。C程序从一个位置复制媒体文件到另一个
大概'功课。 –
请考虑使用fgets(3)而不是scanf(3)。 scanf(3)存在各种问题。请在这里看到,http://c-faq.com/stdio/scanfprobs.html – dmp