• 0

[C++] Confused


Question

Been trying to tackle this problem for a while now...

I'm trying to work with some zlib values but getting really confused...

First here are all the header-ish info needed to understand:

typedef struct z_stream_s {
	Bytef	*next_in;  /* next input byte */
	uInt	 avail_in;  /* number of bytes available at next_in */
	uLong	total_in;  /* total nb of input bytes read so far */

	Bytef	*next_out; /* next output byte should be put there */
	uInt	 avail_out; /* remaining free space at next_out */
	uLong	total_out; /* total nb of bytes output so far */

	char	 *msg;	  /* last error message, NULL if no error */
	struct internal_state FAR *state; /* not visible by applications */

	alloc_func zalloc;  /* used to allocate the internal state */
	free_func  zfree;   /* used to free the internal state */
	voidpf	 opaque;  /* private data object passed to zalloc and zfree */

	int	 data_type;  /* best guess about the data type: binary or text */
	uLong   adler;	  /* adler32 value of the uncompressed data */
	uLong   reserved;   /* reserved for future use */
} z_stream;

typedef z_stream FAR *z_streamp;

typedef Byte  FAR Bytef;

typedef unsigned char  Byte;

I have a z_streamp, and want to get a string version of *next_in that can be displayed in a messagebox. I usually use C# so all these pointers and incompatible string types have been confusing me :|

From what I understand, the z_streamp object I have is actually a pointer to a z_stream_s, which contains the *next_in value , which is a pointer to a Bytef which is actually a Byte which is actually an unsigned char... so how do I go from a z_streamp to a lpcstr of *next_in's value?

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

There's no string type in C. An LPCSTR is actually a long pointer to a null-terminated char array (which is what C strings are). In other word an LPCSTR is a char * (the pointer points to the first char in the array, to get the rest you simply increment the pointer once for each character, because the chars in the array all follow each other).

next_in most likely points to the first char in an array, while avail_in tells you how many chars are in it. If you wanted to read a single string, you would copy each char into your own array until you hit \0 (the null-termination character), which indicates the end of the string. This could happen in a single z_stream_s, or be split over several.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.