[英]How to copy a image to a Directory in C language
我試圖使用文件打開和寫入文件方法來復制圖像文件,但是啟用了實現圖像的功能。因此,請幫助我提供代碼以及所需的頭文件。
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);
我嘗試過這個...
嘗試:
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);
瓦爾特
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.