KMP-MPI/util.c

33 lines
586 B
C

#include <stdio.h>
#include <malloc.h>
void print_array(int *array, int length) {
if (length == 0) {
printf("\n");
return;
}
printf("|");
for (int i = 0; i < length; ++i) {
printf("%d|", array[i]);
}
printf("\n");
}
char *read_file(char *filepath, int *len) {
FILE *f = fopen(filepath, "r");
fseek(f, 0, SEEK_END);
*len = ftell(f);
fseek(f, 0, SEEK_SET);
char *content = (char *) malloc(sizeof(char) * (*len + 1));
fread(content, 1, *len, f);
content[*len] = '\0';
fclose(f);
return content;
}