Many of the methods found on the network will lose characters when extracting the string, here is the workaround:
Http://stackoverflow.com/questions/21186535/compressing-decompressing-char-array-using-zlib-some-characters-missing
Based on this, the author modified a bit, because it is a beginner, only according to the compiler does not error the principle of modified a bit, can run
Open vc++6.0 new Console program, configure the Zdll.lib, put Zlib1.dll in the right place
The main program main.cpp is as follows
#include <string.h>#include<stdio.h>#include<stdlib.h>#include"Zlib.h"intMain () {Const Char*istream ="some foo kanji"; ULong Srclen= strlen (IStream) +1;//+1 for the trailing ' + 'ULong Destlen = Compressbound (Srclen);//should estimate size//needed for the bufferUnsignedChar* Ostream = (unsignedChar*)malloc(Destlen); intres = compress (Ostream, &destlen, (ConstUnsignedChar*) IStream, Srclen); //Destlen is now the size of actuall buffer needed for compression//You don ' t want to uncompress whole buffer later, just the used part if(res = =z_buf_error) {printf ("Buffer was too small!\n"); return 1; } if(res = =z_mem_error) {printf ("Not enough memory for compression!\n"); return 2; } unsignedChar*i2stream =ostream; Char* O2stream = (Char*)malloc(Srclen); ULong DestLen2= Destlen;//Destlen is the actual size of the compressed buffer intDes = uncompress ((unsignedChar*) O2stream, &Srclen, I2stream, destLen2); printf ("%s\n", O2stream); return 0;}
Accessories download
C language uses zlib to implement gzip compression and gzip decompression of text characters