wb = open new binary file for writing, if file exists with same name, it will be truncated to 0 bytes ab = open new binary file for writing, if file exists with same name, new data would be written at end of file. This may lead to undesired results if file already exists. you should check if a file exists before opening it in wb mode :
#include<stdlib.h>
#include<stdio.h>
#define MAX 1024
int main(int argc,int **argv){
FILE \*fsource,\*fdest;
size\_t in;
int buf\[MAX\];
char c = 'n';
fsource = fopen("F:\\\\a.jpg.rar","rb");
//-----------Check if file exists---------
fdest = fopen("D:\\\\a.jpg","r");
if(fdest!=NULL){
fclose(fdest);
printf("Destination file already exists, do you want to overwrite?\\t");
scanf("%c",&c);
if(c!='Y' && c!='y'){
fclose(fSource);
return 1;
}
}
//---------------------------------------
fdest = fopen("D:\\\\a.jpg","wb");
if(fsource == NULL || fdest == NULL)
perror("open error");
while((in = fread(buf,sizeof(int),MAX,fsource)) != 0){
fwrite(buf,sizeof(int),in,fdest);
fflush(fdest);
}
fclose(fsource);
fclose(fdest);
return EXIT\_SUCCESS;
}