title: deflate and inflate (zlib.h) in C
body: <p>I am trying to implement the zlib.h deflate and inflate functions to compress and decompress a char array (not a file).</p>
  
  <p>I would like to know if the following syntax is correct ? Am I missing something or defined something incorrectly ?</p>
  
  <pre class="lang-c prettyprint-override"><code>char a[50] = "Hello World!";
  char b[50];
  char c[50];
  
  // deflate
  // zlib struct
  z_stream defstream;
  defstream.zalloc = Z_NULL;
  defstream.zfree = Z_NULL;
  defstream.opaque = Z_NULL;
  defstream.avail_in = (uInt)sizeof(a); // size of input
  defstream.next_in = (Bytef *)a; // input char array
  defstream.avail_out = (uInt)sizeof(b); // size of output
  defstream.next_out = (Bytef *)b; // output char array
  
  deflateInit(&amp;defstream, Z_DEFAULT_COMPRESSION);
  deflate(&amp;defstream, Z_FINISH);
  deflateEnd(&amp;defstream);
  
  printf("Deflate:\n%lu\n%s\n", strlen(b), b);
  
  // inflate
  // zlib struct
  z_stream infstream;
  infstream.zalloc = Z_NULL;
  infstream.zfree = Z_NULL;
  infstream.opaque = Z_NULL;
  infstream.avail_in = (uInt)sizeof(b); // size of input
  infstream.next_in = (Bytef *)b; // input char array
  infstream.avail_out = (uInt)sizeof(c); // size of output
  infstream.next_out = (Bytef *)c; // output char array
  
  inflateInit(&amp;infstream);
  inflate(&amp;infstream, Z_NO_FLUSH);
  inflateEnd(&amp;infstream);
  
  printf("Inflate:\n%lu\n%s\n", strlen(c), c);
  </code></pre>