-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
40 lines (38 loc) · 1.18 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include "Container.h"
#include "Random.h"
#include<cstdio>
//------------------------------------------------------------------
// Main method: program starting point.
//------------------------------------------------------------------
int main(int argc, char *argv[]) {
Random::initRandom();
if (argc != 3) {
printf("Incorrect arguments format!\n"
"Correct:\n"
"AVS_HW1 in_file out_file\n");
return 0;
}
FILE *fin = fopen(argv[1], "r");
if (fin == nullptr) {
printf("File %s is unavailable to read from!\n", argv[1]);
return 0;
}
FILE *fout = fopen(argv[2], "w");
if (fout == nullptr) {
printf("File %s is unavailable to write to!", argv[2]);
return 0;
}
Container *cont = Container::createContainer(fin);
if (cont == nullptr) {
printf("Bad input file!\n");
fprintf(fout, "Bad input file!");
return 0;
}
fprintf(fout, "Container before changes:\n");
cont->writeContainerToFile(fout);
cont->removeLesserThanAverage();
fprintf(fout, "Container after changes:\n");
cont->writeContainerToFile(fout);
delete cont;
return 0;
}