much prettier than mine i must say.
as a stand alone program i wouldn't need all the specific file closeing
but as a function i need more specifics, like so is much better more like something i would use.
maybe this
Code:
#include <stdio.h>
#include <malloc.h>
#define CloseUp() if(fin)fclose(fin);if(fout)fclose(fout);if(buf)free(buf);
int main(void)
{
FILE* fin,* fout;
int filesize;
char* buf = NULL;
if(!(fin = fopen("C:\\filein.xxx","rb")))
{
printf("Unable To Open Input File\n");
return -1;
}
if(!(fout = fopen("C:\\fileout.xxx","wb")))
{
printf("Unable To Open Output File\n");
CloseUp();
return -1;
}
fseek(fin,0,SEEK_END);
if(!(filesize = ftell(fin)))
{
CloseUp();
return 0;
}
fseek(fin,0,SEEK_SET);
if(!(buf = (char*) malloc(filesize)))
{
printf("Out Of Memory\n");
CloseUp();
return -1;
}
if(fread(buf,1,filesize,fin) < filesize)
{
printf("File Read Error\n");
CloseUp();
return -1;
}
if(fwrite(buf,1,filesize,fout) < filesize)
{
printf("File Write Error\n");
CloseUp();
return -1;
}
CloseUp();
return 0;
}
yes thats much better...
::edit:: still a little over complicated... in my opinion, im just waiting for Salem to smoke me with something better, which he undoubtably has.