Home > Back-end >  For help! C zlib cannot read gz file
For help! C zlib cannot read gz file

Time:12-08

I want to use zlib library to read a gz file binary data, but gzread () and gzgets () can not read clearly, and automatically quit program

Code:
 
# include & lt; Zlib. H>
# include & lt; Iostream>
# include & lt; String>
using namespace std;

Int main ()
{
Char * filename="TS21z_X_R2_000100. Gz";

GzFile GZFP=gzopen (filename, "rb");

If (GZFP==NULL)
{
Printf (" error "\ n");
return false;
}

//distribution of 4 bytes (float)
Char data [4].
Memset (data, 0, sizeof (data));

//read 4 bytes
Gzread (GZFP, data, 4);
//gzgets (GZFP, data, 4);
Printf (" \ n % f ", * (float *) data);
Gzclose (GZFP);
Printf (" successfully read earthquake data \ n ");

return 0;
}

CodePudding user response:

If it is a binary is not the same, you need to specify the parameters such as the "rb" if there are other parameters, the building Lord your check

CodePudding user response:

Zlib uncompress gzip
https://www.cnblogs.com/guoxiaoqian/p/4315195.html
  • Related