title: How do I define and pass in a file name to fopen() from command line?
body: <p>I have the following program that writes a user's input to a file. Currently the file to be written to is predefined; however, I was wanting allow the user to define the file name from command prompt. What would be the best way to add this functionality? I am having trouble getting my head around how I would make the string entered by the user an argument in the fopen() function. Should I use scanf() or create another getchar() while loop store the chars in an array and then create a variable as the argument of fopen() or something?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main()
  {
      char c;
      FILE *fp;
  
      fp = fopen("file.txt", "w");
  
      while ((c = getchar()) != EOF)
      {
          putc(c, fp);
      }
  
      return 0;
  }
  </code></pre>