-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaggregate.c
62 lines (54 loc) · 2.01 KB
/
aggregate.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LINE_LENGTH 128
#define MAX_COMMAND_LENGTH 512
int main() {
char line[MAX_LINE_LENGTH];
int htrLength = 0;
FILE *inputFile = fopen("output.txt", "r");
FILE *returnFile = fopen("return.txt", "w");
FILE *lengthFile = fopen("length.txt", "w");
FILE *outHtrFile = fopen("outhtr.txt", "w");
FILE *countFile = fopen("count.txt", "w");
fclose(returnFile);
fclose(lengthFile);
fclose(outHtrFile);
fclose(countFile);
returnFile = fopen("return.txt", "r");
outHtrFile = fopen("outhtr.txt", "a");
lengthFile = fopen("length.txt", "a");
countFile = fopen("count.txt", "a");
while (fgets(line, MAX_LINE_LENGTH, inputFile) != NULL) {
char command[MAX_COMMAND_LENGTH];
snprintf(command, MAX_COMMAND_LENGTH, "nissy solve htr \"%s\" | tee -a return.txt", line);
system(command);
}
while (fgets(line, MAX_LINE_LENGTH, returnFile)) {
char *open_paren = strchr(line, '(');
char *close_paren = strchr(line, ')');
if (open_paren != NULL && close_paren != NULL) {
char number_str[5];
int num_length = close_paren - open_paren - 1;
if (num_length > 0 && num_length < sizeof(number_str)) {
strncpy(number_str, open_paren + 1, num_length);
number_str[num_length] = '\0';
htrLength = atoi(number_str);
fprintf(lengthFile, "%s\n", number_str);
fflush(stdout);
}
}
}
fclose(lengthFile);
fseek(inputFile, 0, SEEK_SET);
lengthFile = fopen("length.txt", "r");
fseek(lengthFile, 0, SEEK_SET);
while (fgets(line, MAX_LINE_LENGTH, inputFile) != NULL) {
fflush(stdin);
fscanf(lengthFile, "%d\n", &htrLength);
char command[MAX_COMMAND_LENGTH];
snprintf(command, MAX_COMMAND_LENGTH, "nissy solve htr -c -M %d \"%s\" | tee -a count.txt", htrLength, line);
system(command);
}
return 0;
}