Fix read from file
This commit is contained in:
parent
c25a0a5045
commit
f312ca2205
1
data/pattern.txt
Normal file
1
data/pattern.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
mamma
|
1
data/text.txt
Normal file
1
data/text.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
testo di esempio mamma altra mamma esempio prova mammamma esempio mamma
|
7
main.c
7
main.c
@ -100,11 +100,8 @@ void find_end(int residue, char *pattern, char *text, int **matches, int *match_
|
|||||||
}
|
}
|
||||||
|
|
||||||
void initialize() {
|
void initialize() {
|
||||||
text = "testo di esempio mamma altra mamma esempio prova mammamma esempio mamma";//read_file("data/text.txt", &text_len);
|
text = read_file("data/text.txt", &text_len);
|
||||||
pattern = "mamma";//read_file("data/pattern.txt", &pattern_len);
|
pattern = read_file("data/pattern.txt", &pattern_len);
|
||||||
|
|
||||||
text_len = strlen(text);
|
|
||||||
pattern_len = strlen(pattern);
|
|
||||||
|
|
||||||
printf("text: %s\n", text);
|
printf("text: %s\n", text);
|
||||||
printf("pattern: %s\n", pattern);
|
printf("pattern: %s\n", pattern);
|
||||||
|
3
util.c
3
util.c
@ -37,8 +37,9 @@ char *read_file(char *filepath, int *len) {
|
|||||||
*len = ftell(f);
|
*len = ftell(f);
|
||||||
fseek(f, 0, SEEK_SET);
|
fseek(f, 0, SEEK_SET);
|
||||||
|
|
||||||
char *content = (char *) malloc(sizeof(char) * (*len + 1));
|
char *content = (char *) malloc(sizeof(char) * (*len));
|
||||||
fread(content, 1, *len, f);
|
fread(content, 1, *len, f);
|
||||||
|
*len = *len - 1;
|
||||||
content[*len] = '\0';
|
content[*len] = '\0';
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
Loading…
Reference in New Issue
Block a user