title: C splitting character array read from a file by \n (newline character), strange output
body: <p>I am reading a raw text file into a character array and then I want to split the data line by line based on "\n". My code is attached, but I get very strange output.</p>
  
  <p>INPUT FILE is a .txt file created with VIM on Windows, and it looks like:</p>
  
  <pre><code>london
  manchester
  britain
  ...
  </code></pre>
  
  <p>CODE (ignoring some var declarations):</p>
  
  <pre><code>....
  char * buffer = 0;
  long length;
  fl = fopen ("file.txt", "r");
  if (fl){
    fseek (fl, 0, SEEK_END);
    length = ftell (fl);
    fseek (fl, 0, SEEK_SET);
    buffer = malloc (length);
    if (buffer){
      fread (buffer, 1, length, fl); 
    }
    fclose (fl);
    printf(buffer)
  }else{
    printf("data file not found");
    return -1;
  }
  
  char str[80] = "london\nmanchester\nbritain";
  char* entity = strtok(buffer, "\n");  //LINE-A, replacing 'buffer' with 'str' the output is correct.
  while (entity != NULL) {
    printf("%s\n", entity);  //this prints strange output as shown below
    entity = strtok(NULL, "\n");
  }
  </code></pre>
  
  <p>....</p>
  
  <p>OUTPUT:</p>
  
  <pre><code>ondon
  anchester
  ritain
  </code></pre>
  
  <p>The first character is always missing.</p>
  
  <p>However, if I replace "buffer" with "str" the declared character array with the same content as the file everything works as expected.</p>
  
  <p>I do not understand why I am getting this error. Any advice please.</p>
  
  <p>Mnay thanks!</p>