title: Sort strings by using pointers
body: <p>I'm a beginner in programming and my lectures now are on the topic of pointers. I'm supposed to enter strings from keyboard (up to 40) and then sort them alphabetically.</p>
  
  <p>Requirements are that inputting should break as soon as "empty" string is entered, pointers to string should be stored in an array, when sorting I should move pointers to strings and I should make use of <code>strcmp</code> function.</p>
  
  <p>I've stared to write my code and would like to ask you if I'm on the right track. I was advised to store strings in a two-dimensional <code>char</code> array but the problem is the program keeps asking about input even if I enter an empty line (which, I suppose, should be by just pressing <code>Enter</code>). Secondly, I'd like to ask you about the best algorithm for sorting strings considering I'm not experienced in sorting altogether.</p>
  
  <p><strong>EDIT</strong> I made some changes in my code and it gives the output I expected, sorts strings alphabetically. However, I'd greatly appreciate an opinion of someone more experienced in C if  there are any major flaws in my code and maybe some improvements I could make. In the part I don't understand a pointer is assigned an address, but is the way I created the pointer array really the most efficient? I'm aware I could have used <code>malloc</code> but I'd like to use a 2D array just like I did.</p>
  
  <pre><code>int count = 0;
  char arr[40][100];
  char (*poi[40])[100]; //Is the array of pointers declared right?
  
  for (int i = 0; i &lt; 40; i++)
  {
      fgets(arr[i], 101, stdin);
      count++;
      if (strcmp(arr[i], "\n") == 0)
      {
          break;
      }
  }
  
  printf("\n");
  
  for(int i = 0; i &lt; count; i++)
  {
      poi[i] = &amp;arr[i]; //I don't really understand how this part works, seems to work though 
  }
  
  for(int i = 0; i &lt; count - 1; i++)
  {
      for(int j = i + 1; j &lt; count; j++)
      {
          if(strcmp(*poi[i], *poi[j]) &gt; 0) //if I type here strcmp(arr[i], arr[j]) the output is not sorted properly, why?
          {
              char (*temp)[100] = poi[i];
              poi[i] = poi[j];
              poi[j] = temp;
  
          }
      }
  }
  
  
  //returns sorted strings    
  for (int i = 0; i &lt; count; i++)
  {
      printf("%s", *poi[i]);
  }
  </code></pre>