Jump to content
  • Advertisement
Sign in to follow this  
Arenth

Reading into a struct from a file.

This topic is 4806 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

Well I was wondering if I could do in C what I could do in VB. That is to read a struct from a file in VB Dim whatever as someStruct Get #FileHandle,, someStuct Is it possible to do that in C or should I just read in each individual member?

Share this post


Link to post
Share on other sites
Advertisement
You can read an entire structure like so:

someStruct myStruct;
fread(&myStruct,sizeof(myStruct),1,pFile);


Where pFile is a FILE* returned from fopen.

You need to look out for padding and alignment issues though. If you write the whole struct to a file, and read it in, you won't have any problems. It's only if you write the data members individually, and then read the whole struct that you need to look out for padding and things.

Share this post


Link to post
Share on other sites
Well the file I would be reading in from was actually generated by VB. And VB as AFAIK doesn't pad anything.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!