title: c - Segmentation faults while opening file
body: <p>I'm getting really confused right now. I want to create a file and write to it a string which was created before. But when the following code gets executed there happens the segmentation fault error and the program terminates. </p>
  
  <pre><code>FILE* output;
  output = fopen("test.txt", "w");
  fprintf(output, line);
  fclose(output);
  </code></pre>
  
  <p>The line is declared as the following.</p>
  
  <pre><code>char* line = NULL;
  line = malloc(1048576 + 1);
  </code></pre>
  
  <p>First I've considered that the error appears because of the malloc, but this code isn't working either:</p>
  
  <pre><code>FILE* output;
  output = fopen("test.txt", "w");
  fprintf(output, "LBASDHASD");
  fclose(output);
  </code></pre>
  
  <p>What am I doing wrong? In the code which runs before that lines I've used a file pointer too but the file is already closed.</p>