title: Sorting string arrays with fgets
body: <p>I'm trying to create a program which takes an integer value which then determines the amount of strings that can be inputted, this is looped twice. Once the two sets of strings have been inputted my program should sort them and output them  based on their lengths in descending order. When I output the results I don't get what I should be getting.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  int main(void)
  {
  
      int i, num_of_str;
      //int j;
      //int a;
      //int n;
      char input[100];
  
      scanf("%d", &amp;num_of_str);
  
      char** strings = malloc(num_of_str * sizeof(char*));
  
      for (i = 0; i &lt; num_of_str; i++) {
  
          fgets(input, 100, stdin);
          strings[i] = malloc(strlen(input) * sizeof(char*));
          strcpy(strings[i], input);
      }
  
      scanf("%d", &amp;num_of_str);
  
      for (i = 0; i &lt; num_of_str; i++) {
  
          fgets(input, 100, stdin);
          strings[i] = malloc(strlen(input) * sizeof(char*));
          strcpy(strings[i], input);
      }
  
      int a;
      int b;
      char* temp;
  
      for (a = 0; a &lt; num_of_str; a++) {
          for (b = a + 1; b &lt; num_of_str; b++) {
              if (strlen(strings[a]) &lt; (strlen(strings[b]))) {
  
                  temp = strings[a];
                  strings[a] = strings[b];
                  strings[b] = temp;
              }
          }
      }
  
      for (a = 0; a &lt; num_of_str; a++) {
          printf("%s\n", strings[a]);
      }
      return EXIT_SUCCESS;
  }
  </code></pre>