-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab4_io.c
More file actions
62 lines (53 loc) · 1.33 KB
/
Copy pathlab4_io.c
File metadata and controls
62 lines (53 loc) · 1.33 KB
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 "lab4_io.h"
void read_data (
const char* input_filename,
int *n,
char **text,
int *num_patterns,
int **m_set,
int **p_set,
char ***pattern_set)
{
FILE *fin = fopen(input_filename, "r");
fscanf(fin, "%d%d", n, num_patterns);
int np = *num_patterns;
*text = (char*) malloc(sizeof(char)*(*n + 1));
fscanf(fin, "%s", *text);
*m_set = (int *) malloc(sizeof(int) * np);
for (int i=0; i<np; i++) {
fscanf(fin, "%d", (*m_set + i));
}
*p_set = (int *) malloc(sizeof(int) * np);
for (int i=0; i<np; i++) {
fscanf(fin, "%d", (*p_set + i));
}
*pattern_set = (char **) malloc(sizeof(char*) * np);
for (int i=0; i<np; i++) {
*(*pattern_set + i) = (char *) malloc(sizeof(char) * (*(*m_set+i) + 1));
fscanf(fin, "%s", *(*pattern_set + i));
}
fclose(fin);
}
// Will contain output code
void write_result (
int *match_counts,
int *matches,
double computation_time)
{
printf("\nTime elapsed: %f\n", computation_time);
}
void format_checker (
int num_patterns,
int *match_counts,
int *matches)
{
int index=0;
for (int i=0; i<num_patterns; i++) {
printf("pattern %d found at %d locations:\n", i, match_counts[i]);
for (int j=0; j<match_counts[i]; j++) {
printf("%d\t", matches[index]);
index++;
}
printf("\n");
}
}