Is there any way to force fwrite() to write in big-endian format no matter what? I am trying to write a MIDI file and they are always big-endian. Converting every value I write to big endian beforehand would be extremely tedious. Ideas?
death_oclock
103
Posting Whiz
Recommended Answers
Jump to Postwrite a wrapper function such as mywrite() and call it instead of fwrite().
Jump to PostHow tedious it is depends on how many different types you need to reverse. If just ints:
typedef unsigned char uchar; union IntBytes { int i; uchar b[sizeof(int)]; }; WriteInt( int n, FILE* fout ) { union IntBytes uBytes; int i; uBytes.i = n; for (i = …
All 8 Replies
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
nucleon
114
Posting Pro in Training
death_oclock
103
Posting Whiz
nucleon
114
Posting Pro in Training
death_oclock
103
Posting Whiz
nucleon
114
Posting Pro in Training
mcriscolo
47
Posting Whiz in Training
mcldev
0
Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.