title: C program not writing to file?
body: <p>My program won't write to the file after input is received. Everything else seems to work as expected.</p>
  
  <p>Where have I gone wrong?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;unistd.h&gt;
  
  int main()
  {
      char fileSelectionInput[20];
  
      printf("Select a file to print to: ");
      gets(fileSelectionInput);
  
      if (access(fileSelectionInput, F_OK ) == -1) {
          puts("It seems that this file does not exist, sorry.");
          return 0;
      }
  
      printf("Okay now you can type text to append\n\n");
  
      FILE* testFile = fopen(fileSelectionInput, "w+");
  
      int writesLeft = 10;
  
      while (writesLeft &gt; 1)
      {
          char textInput[50];
          gets(textInput);
          fputs(textInput, testFile);
          writesLeft--;
      }
  
      fclose(testFile);
  
      return 0;
  }
  </code></pre>