title: C++ zLib Byte array Compressing
body: <p>After getting my first problem solved at <a href="https://stackoverflow.com/questions/16464925/c-zlib-compress-byte-array">C++ zLib compress byte array</a> i faced another problem<br></p>
  
  <pre><code>void CGGCBotDlg::OnBnClickedButtonCompress()
  {
  // TODO: Add your control notification handler code here
  z_const char hello[256];
  hello[0] = 0x0A;
  hello[1] = 0x0A;
  hello[2] = 0x0A;
  hello[3] = 0x0A;
  hello[4] = 0x0A;
  hello[5] = PKT_END;
  hello[6] = PKT_END;
  hello[7] = PKT_END;
  
  Byte compr[256];
  uLong comprLen = sizeof(compr);
  
  int ReturnCode;
  
  ReturnCode = Compress(compr, comprLen, hello, Z_DEFAULT_COMPRESSION);
  g_CS.Send(&amp;compr,comprLen);
  
  }
  
  
  
  int CGGCBotDlg::Compress(Byte Compressed[], uLong CompressedLength, CHAR YourByte[], int CompressionLevel)
   {
  
  int zReturnCode;
  int Len;
  
      for (int i = 0 ; i &lt;= 10240 ; i++)
      {
          if (YourByte[i] == PKT_END &amp;&amp; YourByte[i+1] == PKT_END &amp;&amp; YourByte[i+2] == PKT_END)
              {
                  Len = i - 1;
                  break;
              }
      }
  
  uLong Length = (uLong)(sizeof(YourByte) * 1.0001) + 12;
  
  zReturnCode = compress2(Compressed, &amp;Length, (const Bytef*)YourByte, Len,CompressionLevel);
  
  return zReturnCode;
  
   }
  </code></pre>
  
  <p>Im trying to compress hello[] wich is actually 5 bytes (I want to compress first 5 bytes)<br>
  The expected result after compressing is : <strong>0x78,0x9C,0xE3,0xE2,0x02,0x02,0x06,0x00,0x00,0xCE,0x00,0x33</strong><br>
  But what I get after compressing is just the first 4 bytes of expected result and another bytes are just something else.<p>
  And my second problem is that i want to replcae 256 in Byte compr[256] with the exact number of bytes after decompressing original buffer (which is 12 in my case)<p>
  Would be great if someone correct me<br>
  Thanks</p>