title: Difference between "gets(s);" and "scanf("%s", s);" in C
body: <p>I am writing a program that allows users to enter five names and sorts the names in Alphabet order, two adjacent names seperated by a newline character. Here is my code:</p>
  <pre><code>void sortWords(char s[][100], int n){
      int i, j;
      char *str;
      for(i = 0; i &lt; n-1; i++){
          for(j = n- 1; j &gt; i; j--){
              if(strcmp(s[j], s[j-1]) == -1){
                  strcpy(str, s[j]);
                  strcpy(s[j], s[j-1]);
                  strcpy(s[j-1], str);
              }
          }
      }
  }
  int main(){
      char s[5][100];
      int i;
      for(i = 0; i &lt; 5; i++){
          fflush(stdin);
          //gets(s[i]);      // when I use this statement, my program doesn't work
          scanf(&quot;%s&quot;, s[i]);
      }
      sortWords(s, 5);
      for(i = 0; i &lt; 5; i++){
          printf(&quot;%s &quot;, s[i]);
      }
      return 0;
  }
  </code></pre>
  <p>When I changed the &quot;scanf&quot; in function main to &quot;gets&quot;, after I have entered 5 names, the program just didn't print anything. Can anyone explain it for me, because normally, when I change one of them to the other function, I just have same results.</p>