Насчёт С не знаю, но на С++ (а значит, наверное, и на С) так:
#include
#include
using std::cout;
using std::endl;
typedef enum { enSuccess, enWrongCmdLine, enFileOpenError } __ExitCodes;
int main(int argc, char **argv)
{
if(argc != 3) { cout<<"Usage: "<<argv[0]<<" <in_file> "<<endl; return enWrongCmdLine; }<br>
FILE *_inFile = fopen(argv[1], "r+b"); if(_inFile == 0) { cout<<"Cannot open input file "<<argv[1]<<endl; return enFileOpenError; }<br> FILE *_outFile = fopen(argv[2], "w+b");
if(_outFile == 0)
{
cout<<"Cannot open output file "<<argv[2]<<endl;<br> fclose(_inFile);
return enFileOpenError;
}
char *_buffer[1024];
while(!feof(_inFile) fwrite(_buffer, fread(_buffer, sizeof(_buffer), 1, _inFile), 1, _outFile);
fclose(_inFile); fclose(_outFile);
return enSuccess;
}