title: Why is scanf("%[^\n]s", ...) not capturing a string with spaces?
body: <p>I've been scouring the globe as to why <code>scanf()</code> is not capturing spaces, and the usual solutions such as <code>&quot;%[^\n]s&quot;</code> or <code>&quot;%100s&quot;</code> (setting string large enough to capture input) have not been working.</p>
  <p>The overall goal of my program is to prompt the user to enter a string, and then that string be stored in a .txt file.  I don't believe my problem is arising from <code>fprintf()</code>, rather from the initial console scan.</p>
  <p>Yes, I am a beginner and do not understand the nuances of C.  Apologies for seemingly simple syntactic errors.  Here's what I got.</p>
  <pre><code>#include &lt;stdio.h&gt;  
    
  int main()
  {
      errno_t inputfile;
      FILE *stream;
  
      inputfile = fopen_s(&amp;stream, &quot;inputfile.txt&quot;, &quot;w&quot;);
      printf(&quot;%s&quot;, &quot;Enter a string.  Press ENTER to exit\n&quot;);
  
      char c[100];
      scanf(&quot;%[^\n]s&quot;, c);
      printf(&quot;%100s&quot;, c); //using printf() to check if scanf() worked.  
                          //Messing around with specifier to see if problem 
                          //is in printf(), which doesn't seem to be the case.
  
      fprintf(stream, &quot;%s&quot;, c);
      fprintf(stream, &quot;%s&quot;, &quot;ENTER is a correct ending&quot;);
      fclose(stream);
  
      return 0;
  }
  </code></pre>
  <p>Any help is appreciated.</p>