title: Why fgets takes cursor to next line?
body: <p>I have taken a string from the keyboard using the <code>fgets()</code> function. However, when I print the string using <code>printf()</code>, the cursor goes to a new line. </p>
  
  <p>Below is the code.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int main()
  {
      char name[25];
  
      printf("Enter your name: ");
      fgets(name, 24, stdin);
      printf("%s",name);
  
      return 0;
  }
  </code></pre>
  
  <p>And below is the output.</p>
  
  <pre><code>-bash-4.1$ ./a.out
  Enter your name: NJACK1 HERO
  NJACK1 HERO 
  -bash-4.1$
  </code></pre>
  
  <p>Why is the cursor going to the next line even though I have not added a <code>\n</code> in the <code>printf()</code>?</p>
  
  <p>However, I have noticed that if I read a string using <code>scanf()</code>, and then print it using <code>printf()</code> (without using <code>\n</code>), the cursor does not go to next line.</p>
  
  <p>Does <code>fgets()</code> append a <code>\n</code> in the string ? If it does, will it append <code>\0</code> first then <code>\n</code>, or <code>\n</code> first and then <code>\0</code>?</p>