| 1 |
#include<stdio.h> |
| 2 |
#include<assert.h> |
| 3 |
|
| 4 |
#define ARRSIZE 80 |
| 5 |
|
| 6 |
int main(int argc, char **argv) { |
| 7 |
char arr[ARRSIZE]; |
| 8 |
char *ifilename; |
| 9 |
char *ofilename; |
| 10 |
FILE *ifile; |
| 11 |
FILE *ofile; |
| 12 |
size_t bytes; |
| 13 |
|
| 14 |
if(argc != 3) { |
| 15 |
fprintf(stderr, "%s <input file> <output file>\n", argv[0]); |
| 16 |
return 1; |
| 17 |
} |
| 18 |
ifilename = argv[1]; |
| 19 |
ofilename = argv[2]; |
| 20 |
printf("%s\n", ifilename); |
| 21 |
ifile = fopen(ifilename, "r"); |
| 22 |
if(!ifile) { |
| 23 |
fprintf(stderr, "Could not open source file %s.\n", ifilename); |
| 24 |
return 1; |
| 25 |
} |
| 26 |
ofile = fopen(ofilename, "w"); |
| 27 |
if(!ofile) { |
| 28 |
fprintf(stderr, "Could not open target file %s\n", ofilename); |
| 29 |
fclose(ifile); |
| 30 |
return 1; |
| 31 |
} |
| 32 |
bytes = fread(arr, 1, ARRSIZE, ifile); |
| 33 |
assert(bytes < 80); |
| 34 |
assert(bytes > 0); |
| 35 |
fwrite(arr, 1, bytes, ofile); |
| 36 |
|
| 37 |
fclose(ifile); |
| 38 |
fclose(ofile); |
| 39 |
return 0; |
| 40 |
} |