繁体   English   中英

c程序将媒体文件从一个位置复制到另一个位置

[英]c program to copy media file from one location to another

#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个字节。

问题出在你的第二次open(2)电话中:

outhandle=open(target,O_CREAT|O_BINARY,O_WRONLY,S_IWRITE);
                                      ^        ^

而不是第二个逗号,你可能意味着| 由于该逗号O_WRONLY将是第三个参数,因此mode和文件将没有正确的权限。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM