title: How can I read a known number of strings of unknown size from a .txt file and store each line in a line of a matrix (in C)?
body: <p>Title is pretty self explanatory. I'm almost sure that the end result wouldn't be a matrix as each line would have a different number of columns, so it's more like a array of arrays of variable sizes. It would also be interesting to sort the fragments by size, biggest first. This is what I've tried so far:</p>
  
  <pre><code>int main() {
    char str[MAXLEN], **fragmentsList;
    int number_of_strings, i, max, k;
    printf("Enter .txt file name: ");
    scanf("%s", str);
    printf("How many strings does the file has? ");
    scanf("%d", &amp;number_of_strings);
    FILE *arq;
    arq = fopen(str, "r");
    for (i = 0, max = 0; !feof(arq); i++) {
      while (fscanf("%c") != '\n') {
        max++;
      }
      if (max &gt; k) {
        k = max;
      }
    }
    fclose(arq);
    fragmentsList = malloc(k * sizeof(char));
    *fragmentsList = malloc(number_of_strings * sizeof(char));
    arq = fopen(str, "r");
    for (i = 0; !feof(arq); i++) {
      fscanf(arq, "%s", fragmentList[i]);
    }
    for (i = 0; i &lt; number_of_strings; i++) {
      printf("%s", fragmentList[i]);
    }
    return 0;
  }
  </code></pre>