title: Sorting user input in lexicographical returning memory characters?
body: <p>I am attempting to alphabetically sort user input with a maximum of 10,000 words and a max length of 25 words. I am using 'stop' to end user input prematurely which is running me into some issues. The current program results in the following as output when I try to input hello stop</p>
  
  <pre><code> ▒l▒
  0▒l▒
  A{▒
  e▒
  
  
  
  ▒&amp;
  ▒▒
  ▒▒
  ▒▒
  ▒▒
  ▒l▒
  ▒l▒
  ▒▒;
  ▒Se▒
  ▒
  ▒
  ▒
  ▒
  
  
  
  
  
  ▒!
  Ќl▒
  ▒
  ▒
  ▒
  ▒.X
  
  ▒
  </code></pre>
  
  <p>I am assuming this has to do with my memory allocation but I am not too sure and couldn't find some answers regarding this. Any help would be appreciated, the following is my code (feel free to ignore the lowercase pointer, still working on getting the output to turn into lowercases!)</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include &lt;string.h&gt;
  
  //for using tolower
  #include &lt;ctype.h&gt;
  int main() {
      int i, k, j;
      char abc[25];
      const char *stop = "stop";
      char *p; //using for lowercase
      //using 2d array for max of 10,000 words, max size of words 25
      char str[10000][25], temp[25];
  
      printf("Enter up to 10000 words, type stop to enter the current words:\n");
      while (strncmp(abc, "stop", 5) != 0) {
          scanf("%s", abc);
      }
          //for (i = 0; i &lt; 10000; ++i)
              //scanf("%s[^\n]", str[i]);
  
          for (i = 0; i &lt; 10000; ++i)
              for (k = i + 1; k &lt; 10000; ++k) {
                  //comparing two strings using strcmp() function is used
                  //using strcpy() to copy string to a temp
                  if (strcmp(str[i], str[k]) &gt; 0) {
                      strcpy(temp, str[i]);
                      strcpy(str[i], str[k]);
                      strcpy(str[k], temp);
                  }
              }
  
          //using pointer to converting to lowercase
          //src: https://www.daniweb.com/programming/software-development/threads/57296/how-does-one-tolower-an-entire-string
          for (p = str; *p != '\0'; p++)
              *p = (char) tolower(*p);
  
          //printing words in lexi order
          printf("\nWords in lexicographical order: \n");
          for (i = 0; i &lt; 10000; ++i) {
              puts(str[i]);
          }
          printf("WARNING: Words longer than 25 in length were ignored. \n");
  
          return 0;
  
  }
  </code></pre>