Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

bilstonwarrior

reading & writing files with # of bytes

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

i have 2 programs. the 1st program reads in a binary file and flips all the data in it.... and writes out a new file with all the reversed bits... like so: FILE *in; FILE *out; #define BYTES_TO_READ (32) while (end of file) { fread(&data,BYTES_TO_READ, 1, in); data = ~data; fwrite(&mp3data,BYTES_TO_READ, 1, out); // write out to file } in the 2nd program, the output file from the 1st program is read in, and all the data is flipped. (essentially having the original file''s data again) however, when it is flipped, the data is only spot-on-correct if it is read with the same number of bytes. (ie BYTES_TO_READ is the same in both programs). This is the problem as the 2nd program that reads in the data and reflips it, will read the data in with different number of bytes (this is determined by something else in code that cannot change), so i need to cater for any number of bytes being used to read back in. the question is.... is there a way i can read & write the data in the 1st program in such a way, that the 2nd program will be able to read and flip the bits with any number of bytes used???? here is an example of the 2nd program code: void ReadFile(unsigned int bytes) { fread(&data,bytes, 1, in); data = ~data; // ''data'' is ready to be used } ... somewhere else in the code, this function is called: ReadFile(6144); ReadFile(10); ReadFile(100); // etc THANKS FOR ANY HELP/ADVICE!!! Paul.

Share this post


Link to post
Share on other sites
Advertisement

  • 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!