title: Segfault while using fopen
body: <p>I am receiving a segfault from the second line of the following code: </p>
  
  <pre><code>FILE *output = NULL;
  output = fopen("./output2.txt", "w+");
  </code></pre>
  
  <p>I don't think it is some sort of corrupt memory error because when I change w+ to r. It runs with no segfault.   ALSO, it appears to create the file right before it segfaults.</p>
  
  <p>EDIT: turns out mrbatch is right</p>
  
  <p>All my code for reference:</p>
  
  <pre><code>void writeFile(const char *header, int numRows, int numCols, int **grades, const char  *outFile)
  {
      printf("writefile success\n");
      int i, j;
      FILE *output = NULL;
      output = fopen("./output2.txt", "w+");  // ERROR HERE (I was wrong, keep reading)
      printf("testestestsetsete\n\n\n");    //based off the commenters, this code 
                                            //IS reached but is never printed
  
      fprintf(output, "%s", *header);  //commenters stated error is here
                                       //*header should be header
      fprintf(output, "%d %d\n", numRows, numCols); //output the number or rows and columns at the second line
  
      //output each grades(scores) in the processed 2D array grades
      for(i = 0; i &lt; numRows; i ++ ) {    //loop through all rows
          for( j = 0; j &lt; numCols; j ++ ) //loop through all columns in the i row
          {   
              if( j &lt; numCols - 1 )
                  fprintf(output, "%d ", grades[i][j]);
              else
                  fprintf(output, "%d\n", grades[i][j]);
              //printf("\"%d\" ", score);
          }
          //printf("\n");
      }
  
      fclose(output); 
  </code></pre>
  
  <p>}</p>