谁能解释我是对还是错

谁能解释我是对还是错

main()
{
char source[1560]="mrinalsaikiaismynamenwhatnotiamgreatajajlksjkkslskldklkdklkdlwhgygehehhejhjejdjjjjjljlkkjjjjjjaasasaaasjsjssjskjkjalsjalksjajslkjckljdjfjfjfjffjkllkjldkjlskjlkjkljklklkalksklksjkjskjksjlksjjskjklsjsjskjkjkjjjsjkjjjjjbhbjbbjbjbssjbsjsbsjssjssjhjdjdjjkkmrinalsaikiaismynamenwhatnotiamgreatajajlksjkkslskldklkdklkdlwhgygehehhejhjejdjjjjjljlkkjjjjjjaasasaaasjsjssjskjkjalsjalksjajslkjckljdjfjfjfjffjkllkjldkjlskjlkjkljklklkalksklksjkjskjksjlksjjskjklsjsjskjkjkjjjsjkjjjjjbhbjbbjbjbssjbsjsbsjssjssjhjdjdjjkk";
int ret ;

bz_stream comp_stream;
comp_stream.next_in = source;
comp_stream.avail_in =strlen(source);

comp_stream.avail_out = 502 ;
char arr[comp_stream.avail_out];
comp_stream.next_out =arr;
comp_stream.opaque = NULL;
comp_stream.bzfree = NULL;
comp_stream.bzalloc = NULL;
comp_stream.state = NULL;

BZ2_bzCompressInit(&comp_stream,1,0,0);


printf("length before compression = %d \n",strlen(source));
printf(" string  original is %s \n",(comp_stream.next_in));


if(BZ2_bzCompress(&comp_stream, BZ_FINISH) == BZ_STREAM_END)
{
    printf("copressed Data\n");
    printf("compressed size length = %d \n",(502 - comp_stream.avail_out));
}
printf("compressed string = %s \n",comp_stream.next_out);
Decompress(comp_stream.next_out,(502 - comp_stream.avail_out));
BZ2_bzCompressEnd(&comp_stream);

最佳答案

如果写入了任何数据,next_out的值将更改,就像读取了任何数据,next_in的值将更改一样。换句话说,您试图在压缩数据结束后立即解压缩数据。

关于c - 混淆使用libbz2功能?谁能解释我是对还是错?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33216961/

10-10 16:18