// // Created by Lennart on 02/12/2023. // #include "input_handler.h" #include #include #define INITIAL_CAPACITY 64 const char* read_line(FILE *f, char **buffer, int *capacity) { if(*buffer == NULL) { *buffer = malloc(2 * sizeof (char) * INITIAL_CAPACITY); *capacity = INITIAL_CAPACITY; } int position = 0; while(!feof(f)) { char *res = fgets(*buffer + position, *capacity - position, f); if(res[strlen(res) - 1] == '\n') { return *buffer; } *buffer = realloc(*buffer, 2 * sizeof (char) * *capacity); position += (int) strlen(res); *capacity *= 2; } return *buffer; }