This line would appear to be the main problem:
(uLongf*)strlen(ostream)
You are interpreting a size_t
value as a pointer to a buffer. You are meant to pass the address of an unsigned long
containing the length of the output buffer. Take another look at the documentation for compress
.
On top of that you don't yet understand how C strings work. The assignment operator when used with a char*
lvalue merely copies an address and not the contents of a string. I suggest that you declare your buffers like this:
const char *istream = "istream";
char ostream[120];
I think your program should be something along these lines:
int main(void)
{
const char *istream = "istream";
char ostream[120];
uLongf destLen = sizeof(ostream);
int res = compress((Bytef*)ostream, &destLen, (Bytef*)istream, strlen(istream));
return 0;
}
Note that I wrote the code assuming that you are using a C compiler. And hence int main(void)
.