/*
* Zpracovani binarniho souboru
*/
#include <stdio.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
unsigned short int i,cislo;
FILE *f1, *f2;
char buffer[0x10000]; // = 65536 B = 64 kB
int precteno,zapsano;
int main(int argc, char *argv[]) {
//
// Uvodni kontroly
//
if (argc<3) {
printf("\n\
Program zkopiruje soubor\n\
Syntax: %s zdrojovy_soubor cilovy_soubor\n\n", argv[0]);
return 1;
}
if ( (f1 = fopen(argv[1],"r"))== NULL ) {
printf("\nCHYBA pri otevirani souboru %s - %s\n\n", argv[1], strerror(errno));
return 1;
}
if ( (f2 = fopen(argv[2],"w"))== NULL ) {
printf("\nCHYBA pri otevirani souboru %s - %s\n\n", argv[2], strerror(errno));
return 1;
}
//
// Hlavni cyklus
//
while ( (precteno=fread(buffer,1,sizeof(buffer),f1)) > 0 ) {
zapsano=fwrite(buffer,1,precteno,f2);
if (zapsano!=precteno) {
printf("\nCHYBA pri kopirovani souboru\n\n");
return 1;
}
}
//
// Zaverecne kontroly
//
if ( fclose(f1)==EOF ){
printf("\nCHYBA pri zavirani souboru %s - %s\n\n", argv[1], strerror(errno));
return 1;
}
if ( fclose(f2)==EOF ){
printf("\nCHYBA pri zavirani souboru %s - %s\n\n", argv[2], strerror(errno));
return 1;
}
return 0;
}