Насчёт С не знаю, но на С++ (а значит, наверное, и на С) так: #include <iostream> #include <stdio.h> 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> <out_file>"<<endl; return enWrongCmdLine; }
#include <iostream>
#include <stdio.h>
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> <out_file>"<<endl; return enWrongCmdLine; }
FILE *_inFile = fopen(argv[1], "r+b"); if(_inFile == 0) { cout<<"Cannot open input file "<<argv[1]<<endl; return enFileOpenError; }
FILE *_outFile = fopen(argv[2], "w+b");
if(_outFile == 0)
{
cout<<"Cannot open output file "<<argv[2]<<endl;
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;
}