1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
fseek(f1, 0, SEEK_END);
long Size = ftell(f1);
rewind(f1);
buffer=(char*) malloc(sizeof(char)*Size);
if(buffer==NULL){
MessageBoxA(NULL,"Memory allocation has failed!", "ERROR!", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
size_t result = fread(buffer, 1, Size, f1);
if(result!=Size){
MessageBoxA(NULL,"Error while reading the file!", "ERROR!", MB_OK | MB_ICONEXCLAMATION);
return 0;
}
remove("test.txt");
f2 = fopen("test.txt","a+");
for(int y=0; y<(sizeof(buffer)-sizeof(char)); y++){
fwrite(buffer, (sizeof(buffer)-1), 1, f2);
}
f1 = f2;
|