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 PostIf you don't mind including <arpa/inet.h>, you can use the htonl() function:
int newval = htonl(origval);
The "h" on the front is for "host" and the "n" is for network, "l" on the end for "long" (there is also a version for 16-bit integers). Hence, "Host to …
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.