title: Writing user input to a file in C programming
body: <p>I am working on a program to write user input to a file and then search for a specific record in the file and output it to the screen.</p>
  
  <p>I tried using fgets and also fputs, but I haven't been successful. Here's what I have so far.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;string.h&gt;
  
  main ()
  {
      FILE *fileptr;
      char id [30];
      char name [47];
      char amt[50];
  
      fileptr = fopen("C:\\Users\\Andrea\\Documents\\Tester.txt", "w");
      if (fileptr == NULL) {
          printf("File couldn't be opened\n\a\a");
          fclose(fileptr);
          exit(0);
      }
  
      printf("Enter name: \n");
      fscanf(fileptr, "%c", name);
      fputs(name, fileptr);
      fclose(fileptr);
      printf("File write was successful\n");
      return 0;
  }
  </code></pre>