title: Is fgets more effective than scanf when comparing strings in C?
body: <p>When working on the following code:</p>
  
  <pre><code>#define MAX_NAME_LENGHT 256
  int main(void)
  {
     char name[MAX_NAME_LENGHT];
     printf("Enter your name: \n");
     scanf("%s", name);
     if(strncmp(name, "John Smith", 10) == 0)
     {
        printf("Hello, John Smith!\n");
     }
     else
     {
        printf("Intruder!!!\n");
     }
     return 0;
  }
  </code></pre>
  
  <p>Many errors occur and despite inputing <code>John Smith</code> the output prints <code>Intruder!!!</code>. However, when I replace </p>
  
  <pre><code>scanf("%s", name); 
  </code></pre>
  
  <p>with </p>
  
  <pre><code>fgets(name, sizeof(name), stdin); 
  </code></pre>
  
  <p>the output prints <code>Hello, John Smith!</code> Why is this?</p>