All I want is to store the content of a text file in a char array. In any other language this is easily achievable. With Ruby, in 1 line of code, if I'm not mistaken.
Anyways, the content and size of the file is unknown. So far I have this:
#include <string.h> #include <stdio.h> #include <pcre.h> int main() { /* open json-sample-object and start reading it */ FILE *fin; fin = fopen("/home/negrabee/playin-with-c/json-sample-object", "r"); if(fin == NULL) { printf("Error opening file\n"); return 1; } char buffer[128]; while(!feof(fin)) { fgets(buffer, 128, fin); //this is where I blank out } }
So at that point in the loop, I'm unsure what to do. I mean I would like to concatenate a char array with 'buffer' but to that I would need to resize the array each time. Which is surprisingly a lot to ask for.
Any ideas guys?