title: C: Using malloc and realloc to double the initial memory
body: <p>I'm still learning how dynamic memory works and new to the malloc, realloc business and need real help with this one. My aim here is to read a file containing some paragraph and dynamically store the lines in an array of strings. Initial number of lines that can be stored is 10 if this is insufficient we need to double the number of memory and print a message with line number where we doubled the memory.</p>
  
  <pre><code>int main(int argc, char* argv[])
  {
    char* lines;
    int line = 0;
  
    lines = malloc(10 * sizeof(char));
    while(fgets(lines, sizeof(lines), stdin)
    {
      if(lines[strlen(lines)-1] != '\n')
      {
         lines = realloc(lines, 5);
         line++;
         printf("Reallocating to %d lines", line);
      { 
    }
  }
  </code></pre>
  
  <p>I'm completely stuck and need any help I could find.</p>