title: C program with fully justification of text from file
body: <p>Here is my problem statement:</p>
  
  <p><a href="https://i.stack.imgur.com/Y9Kul.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y9Kul.jpg" alt="enter image description here"></a></p>
  
  <p>I have a small question related to a portion of code which I can't find a proper solution to. Again I'm not necessarily asking for a full solution I just hit a deadend. I need to read from a file lines (Don't know their lengths) find the maximum length of a line and add spaces between words on each line, evenly, so that they are fully justified (all lines have the same size as the max one).</p>
  
  <p>Here is my code so far:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  int main() {
      FILE *f;
      char *word;
      int j, i, m, n, c, k, z;
      char aux[255] = "", aux1[255];
      i = 0;
      j = 0;
      char file[100][100];
      char s[100];
      f = fopen("user_input.txt", "r");
      m = 0;
  
      while (fgets(file[i], sizeof(file[i]), f)) {
          if (m &lt; strlen(file[i]) - 1)
              m = strlen(file[i]) - 1;
          i++;
      }
  
      for (j = 0; j &lt; i; j++) {
          n = 0;
  
          for (k = 0; k &lt; strlen(file[j]); k++)
              if (file[j][k] == ' ')
                  n++;
  
          c = (m - strlen(file[j])) / n;
  
          for (z = 0; z &lt; c; z++)
              aux[z] = ' ';
  
          for (k = 0; k &lt; strlen(file[j]); k++)
              if (file[j][k] == ' ') {
                  strcpy(aux1, file[j] + k + 1);
                  strcat(file[j], aux);
                  strcat(file[j], aux1);
              }
  
          printf("%s", file[j]);
      }
  }
  </code></pre>