title: Segmentation Fault while reading specificly 13 lines
body: <pre><code>char **getLines(FILE *pFile)
  {
    int nLines = 0;
    size_t memRes = 0;
    char **lines = malloc(memRes);
    char *current = (char*) malloc(20);
    while(fgets(current, 20, pFile) != NULL)
      {
        memRes += sizeof(char*);
        lines = realloc(lines, memRes);
        lines[nLines] = malloc(20);
        strcpy(lines[nLines], current);
        nLines++;
      }
    free(current);
    return lines;
  }
  
  void printLines(char **lines)
  {
    int lineI = 0;
    while(lines[lineI] != NULL)
      {
        printf("%s", lines[lineI]);
        lineI++;
      }
  }
  </code></pre>
  
  <p>First I get the lines then I print them. The odd thing about it is that my code fails when it has read exactly 13 lines of code and then prints them. I get a segmentation fault after printing the last line. It works with 12 lines and with 14 lines perfectly.</p>