1
0
rwu_particles_informatikpro.../utils.c

28 lines
435 B
C
Raw Normal View History

2020-03-18 11:29:08 +00:00
#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;
}