title: Read the entire contents of a file to c char *, including new lines
body: <p>I'm looking for a cross platform (Windows + Linux) solution to reading the contents of an entire file into a <code>char *</code>. </p>
  
  <p>This is what I've got now:</p>
  
  <pre><code>FILE *stream;
  char *contents;
  fileSize = 0;
  
  //Open the stream
  stream = fopen(argv[1], "r");
  
  //Steak to the end of the file to determine the file size
  fseek(stream, 0L, SEEK_END);
  fileSize = ftell(stream);
  fseek(stream, 0L, SEEK_SET);
  
  //Allocate enough memory (should I add 1 for the \0?)
  contents = (char *)malloc(fileSize);
  
  //Read the file 
  fscanf(stream, "%s", contents);     
  
  //Print it again for debugging
  printf("Read %s\n", contents);
  </code></pre>
  
  <p>Unfortunately this will only print the first line in the file so I assume that fscanf stops at the first newline character. However I would like to read the entire file including, and preserving, the new line characters. I'd prefer not to use a while loop and realloc to manually construct the entire string, I mean there has to be a simpler way?</p>