Jump to content
  • Advertisement
Sign in to follow this  
briandra3

Parsing void* data

This topic is 4800 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to read in individual files from a .zip file in c++. Using zlib, I can uncompress the file I want in the zip and get the data into a void* variable. How can I then parse the void* data? I know what type of data should be in the void* variable. I also know how to parse text and binary files using the FILE class. Can I do a similar thing with the void*? Thanks, Brian

Share this post


Link to post
Share on other sites
Advertisement
The void * pointer is basicly an un-typed pointer. You can treat it like as you like. If you want to convert the data to a byte array, you can do so by casting it:
unsigned short *bytes = (unsigned short *)pData;

You can do same with all other data-types, except it might or might not work. If you want to treat it like binary data, it's most commom to use char * for the data.

Toolmaker

Share this post


Link to post
Share on other sites
Thanks for the reply!

Are there any functions that could be used to parse both files and void* buffers? I would like to be able to load data from either a file or a void* buffer, and it would be the best if I could do both using the same routine.

Share this post


Link to post
Share on other sites
I'd recommend separate functions. Parsing through void*s can get pretty messy because you have to type-cast it for just about anything you want to do with it.

If you put it all into one function its doable, but if you take the time to write two separate functions one for a FILE* and one for a void* you'll thank me in the long run.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!