小编Jum*_*ock的帖子

麻烦测试C中的复制文件功能

好的,所以这可能有一个简单的解决方案,但经过一些搜索和测试后,我仍然困惑.. :(

这是我编写的代码片段:

int main(int argc, char *argv[]){
  int test;
  test = copyTheFile("test.txt", "testdir");
 if(test == 1)
    printf("something went wrong");
 if(test == 0)
    printf("copydone");
 return 0;
}

int copyTheFile(char *sourcePath, char *destinationPath){
    FILE *fin = fopen(sourcePath, "r");
    FILE *fout = fopen(destinationPath, "w");
    if(fin != NULL && fout != NULL){
        char buffer[10000];//change to real size using stat()
        size_t read, write; 

        while((read = fread(buffer, 1, sizeof(buffer), fin)) > 0){
            write = fwrite(buffer, 1, read, fout);
            if(write != read)
                return 1;       
        }//end of …
Run Code Online (Sandbox Code Playgroud)

c io copy path

0
推荐指数
1
解决办法
121
查看次数

标签 统计

c ×1

copy ×1

io ×1

path ×1