title: Xcode Error: “EXC_BAD_ACCESS”
body: <p>I am attempting to compile and run a test C program in Xcode. This program reads 5 symbols from a text file and closes it. The program builds successfully, but when I try to run the program I get the error: GDB: Program received signal: "EXC_BAD_ACCESS" around fclose(in).</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;unistd.h&gt;
  
  int main (int argc, const char * argv[])
  {
      bool b;
      char inpath[PATH_MAX];
      printf("Enter input file path :\r\n");
      std::cin &gt;&gt; inpath;
      FILE *in = fopen(inpath, "r+w");
      char buf[5];
      fread(&amp;buf,sizeof(buf),5,in);
      printf(buf);
      fclose(in);
      return 0;
  }
  </code></pre>
  
  <p>What could be a cause of this?</p>