2014-02-11 24 views
0

我试图使用文件打开和写入文件方法来复制图像文件,但启用实现图像...所以请帮助我与代码一起需要头文件。如何将图像复制到C语言的目录

char ch, source_file[20], target_file[20]; 
    FILE *source, *target; 
    source = fopen("Source", "r"); 
    if(source == NULL) 
    { 
    printf("Press any key to exit...\n"); 
    } 
    target = fopen("Destination", "w"); 
    if(target == NULL) 
    { 
    fclose(source); 
    } 

    while((ch = fgetc(source)) != EOF) 
    fputc(ch, target); 

    printf("File copied successfully.\n"); 

    fclose(source); 
    fclose(target); 

我想这....

+0

所以你的问题是什么? –

+0

你应该开始代码,然后我们看看它。 – smushi

+0

你需要'';你可以使用'fread()'和'fwrite()';你将使用'fopen()';您可能会在公开呼叫中使用'b'作为其中一个标志。 –

回答

0

尝试:

FILE *source, *target; 
int i; 
source = fopen("Source", "rb"); 

if(source == NULL) { printf("Press any key to exit...\n");} //exit(EXIT_FAILURE); 

fseek(source, 0, SEEK_END); 
int length = ftell(source); 

fseek(source, 0, SEEK_SET); 
target = fopen("Destination", "wb"); 

if(target == NULL) { fclose(source); } //exit(EXIT_FAILURE); 

for(i = 0; i < length; i++){ 
    fputc(fgetc(source), target); 
} 

printf("File copied successfully.\n"); 
fclose(source); 
fclose(target); 

瓦尔特

+0

Thnxs它的工作... –

相关问题