1
0
rwu_particles_informatikpro.../utils.c
2020-03-31 15:09:07 +02:00

28 lines
435 B
C

#include <stdio.h>
#include <malloc.h>
#include "utils.h"
#define BUFFER_SIZE 1024
char *readFile(char *path)
{
FILE *file = fopen(path, "r");
char *str = malloc(BUFFER_SIZE);
int c, i = 0, j = 1;
while ((c = fgetc(file)) != EOF)
{
if (i == j * BUFFER_SIZE)
{
str = realloc(str, ++j * BUFFER_SIZE);
}
str[i++] = (char) c;
}
fclose(file);
return str;
}