title: zlib, c and gzread
body: <p>so I'm using the zlib package on Ubuntu. I'm trying to figure out how to use gzopen and gzread correctly, this is what I have so far</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;assert.h&gt;
  #include &lt;zlib.h&gt;
  
  #define NUM_BUFFERS 8
  #define BUFFER_LENGTH 1024
  
  char buf[BUFFER_LENGTH];
  int main(int argc, const char* argv[])
  {
      int status;
      gzFile file;
      file = gzopen("beowulf.txt", "w");
      int counter = 0; /*when the counter reachers BUFFERS_FULL, stop*/
      if(file == NULL)
      {
          printf("COULD NOT OPEN FILE\n");
          return 1;
      }
      while(counter &lt; NUM_BUFFERS)
      {
          status = gzread(file, buf, BUFFER_LENGTH - 2);
          printf("STATUS: %d\n", status);
          buf[BUFFER_LENGTH - 1] = "\0";
          printf("%s\n", buf);
          counter++;
      }
      gzclose(file);
      printf("STATUS: %d\n", status);
      return 0;
  }
  </code></pre>
  
  <p>The <code>gzread("STATUS: %d\n",status);</code> returns -2, and I have no clue why. Any help would be appreciated.</p>