title: How do I remove SEGFAULT here?
body: <p>I created a function to print the contents of a file:</p>
  
  <pre><code>void readFile(char* filename)
  {
  int c ; 
  file = fopen(filename, "r");    
  printf("The contents of the file are:\n");
  while((c = fgetc(file)) != EOF)
  {
      printf("%c", c);
  }   
  return;
  </code></pre>
  
  <p>}</p>
  
  <p>where <code>file</code> is a global variable. GDB gives output as follows:</p>
  
  <pre><code>_IO_getc (fp=0x0) at getc.c:39
  39  getc.c: No such file or directory.
  (gdb) bt
  #0  _IO_getc (fp=0x0) at getc.c:39
  #1  0x000000000040075e in readFile ()
  #2  0x00000000004006d4 in main ()
  </code></pre>
  
  <p>However, the file is present and I get the SEGFAULT <em>after</em> printing the contents of the file. It <em>might</em> be because the buffer here (c) is small but I am not sure. Also, I don't know how do I fix this even if that were the case. Can anyone suggest how do I proceed?</p>
  
  <p><strong>EDIT</strong>
  I call the readFile function only once. Here is my calling function:</p>
  
  <pre><code>int main(int argc, char* argv[])
  {
  char * filename;
  
  filename = argv[1];
  readFile(filename);
  printf("File Handler: %ld", (long)file);
  
  fclose(file);
  return 0;
  }
  </code></pre>