title: What's the error with fgets in this code?
body: <p>Where am I going wrong and why?</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  
  int main()
  {
  char *str;
  int length, i, j, flag = 0;
  
  printf("\n\nEnter string: ");
  fgets(str, 20, stdin);
  printf("You entered: %s", str);
      return 0;
  }
  </code></pre>
  
  <p>There's a problem with the line <code>fgets(str, 20, stdin);</code> line. I cannot figure it out. After entering the string, the compiler just stops working and I get an error saying: <strong>This program has stopped working</strong>. Could you point where am I going wrong and also a workaround for this problem? The standard library defines <code>fgets</code> as:</p>
  
  <pre><code>char * fgets ( char * str, int num, FILE * stream );
  </code></pre>
  
  <p>I'm using <em>Sublime Text 2</em> and <em>GCC on the MinGW shell</em>.</p>
  
  <p>A different question based on the pointer concept:
  Are there any differences between <code>char * str</code>, <code>char* str</code> and <code>char *str</code>?</p>