title: Geany Error code 139: Segmentation fault (Core dumped) using C
body: <p>my overall program creates a new file based on a file name and mode that the user enters, then checks to see if the file exists. Following that it outputs whether file creation was successful. It should be simple, but when I compile and build (successfully) with Geany and run, I get the following error in the terminal window (but only after entering the mode "r+"):</p>
  
  <pre><code>./geany_run_script.sh: line 5:  7395 Segmentation fault      (core dumped) "./test" c
  
  
  ------------------
  (program exited with code: 139)
  Press return to continue
  </code></pre>
  
  <p>Then I ran it with gdb, after reading this</p>
  
  <p><a href="https://stackoverflow.com/questions/21671272/segmentation-fault-core-dump">segmentation fault (core dump)</a></p>
  
  <p>and got this error:</p>
  
  <pre><code>Program received signal SIGSEGV, Segmentation fault.
  _IO_new_fclose (fp=0x0) at iofclose.c:54
  54  iofclose.c: No such file or directory.
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  char filename[100];
  char mode[2];
  
  int main(int argc, char **argv)
  {
      printf("Enter filename:\n&gt;");
      scanf("%s", &amp;*filename);
      printf("Select a mode from the list:\nr reading\nw writing\na append\nr+ reading &amp;   writing (at beginning, overwriting)\nw+ reading &amp; writing (overwrite on existing)\na+ reading &amp; appending (new data appended at end of file)\n&gt;");
      scanf("%s", &amp;*mode);
  
      FILE * fp;
      fp = fopen(filename, mode);
  
      if (fp == NULL)
      {
          printf("Failed to open\n");
      }
      else
      {
          printf("Succesfully opened\n");
      }
      fclose(fp);
  
      return 0;
  }
  </code></pre>
  
  <p>The gdb error comes up after I enter the filename, unlike with Geany where I get the error after I enter mode "r+".</p>
  
  <p>Please help, and simply ask if you need additional data. Thanks in advance.</p>
  
  <p>Edit: I updated the code, and the bit about when I get the error. For some reason, it is now at a different point in the program depending on whether I run it with gdb or with Geany. </p>