首页 技术 正文
技术 2022年11月8日
0 收藏 354 点赞 1,308 浏览 1103 个字

网络上找到的好多方法在解压缩字符串的时候会丢失字符,这里是解决方法:

http://stackoverflow.com/questions/21186535/compressing-decompressing-char-array-using-zlib-some-characters-missing

基于此,笔者修改了一下,由于是初学者,只按照编译器不报错的原则修改了一下,能运行

打开vc++6.0新建控制台程序程序,配置好zdll.lib,把zlib1.dll放置到合适的位置

主程序main.cpp如下

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "zlib.h"int main()
{
const char *istream = "some foo汉字";
uLong srcLen = strlen(istream)+; // +1 for the trailing `\0`
uLong destLen = compressBound(srcLen); // this is how you should estimate size
// needed for the buffer
unsigned char* ostream = (unsigned char*)malloc(destLen);
int res = compress(ostream, &destLen, (const unsigned char *)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 ;
}
if(res == Z_MEM_ERROR){
printf("Not enough memory for compression!\n");
return ;
} unsigned char *i2stream = ostream;
char* o2stream = (char *)malloc(srcLen);
uLong destLen2 = destLen; //destLen is the actual size of the compressed buffer
int des = uncompress((unsigned char *)o2stream, &srcLen, i2stream, destLen2);
printf("%s\n", o2stream);
return ;
}

附件下载

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,117
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,590
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,435
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,206
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,842
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,927