record generator
This commit is contained in:
parent
45e804a350
commit
36035058f2
2 changed files with 13 additions and 2 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
build
|
build
|
||||||
|
tests/2.in
|
||||||
|
|
|
||||||
14
main.c
14
main.c
|
|
@ -83,7 +83,10 @@ int process_args(int argc, char** argv, options* opts)
|
||||||
fprintf(stderr, "No file specified, aborting\n");
|
fprintf(stderr, "No file specified, aborting\n");
|
||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
opts->input = fopen(filename, "r");
|
opts->input = fopen(filename, "r+");
|
||||||
|
if (!opts->input) {
|
||||||
|
opts->input = fopen(filename, "w+");
|
||||||
|
}
|
||||||
if (!opts->input) {
|
if (!opts->input) {
|
||||||
fprintf(stderr, "Error: Cannot open file '%s'\n", filename);
|
fprintf(stderr, "Error: Cannot open file '%s'\n", filename);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
|
|
@ -93,6 +96,14 @@ int process_args(int argc, char** argv, options* opts)
|
||||||
|
|
||||||
void generate_file(options* opts)
|
void generate_file(options* opts)
|
||||||
{
|
{
|
||||||
|
srand(time(0));
|
||||||
|
record rec;
|
||||||
|
for (int i = 0; i < opts->N; i++) {
|
||||||
|
random_record(&rec);
|
||||||
|
print_record(opts->input, &rec);
|
||||||
|
fprintf(opts->input, "\n");
|
||||||
|
}
|
||||||
|
fseek(opts->input, 0, SEEK_SET);
|
||||||
}
|
}
|
||||||
|
|
||||||
void write_file(options* opts)
|
void write_file(options* opts)
|
||||||
|
|
@ -127,7 +138,6 @@ int main(int argc, char** argv)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (opts.generate_data) {
|
if (opts.generate_data) {
|
||||||
srand(time(0));
|
|
||||||
generate_file(&opts);
|
generate_file(&opts);
|
||||||
}
|
}
|
||||||
if (opts.manual_input) {
|
if (opts.manual_input) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue