If you already know how to write bytes to a file, then you only have to put them in a byte array like this:
1 2 3 4 5 6
unsignedchar bytes[4];
// 4125 = 0x0000101D
bytes[0] = x & 0xFF000000; //Contains the big byte (0x00)
bytes[1] = x & 0x00FF0000;
bytes[2] = x & 0x0000FF00;
bytes[3] = x & 0x000000FF; //Contains the little byte (0x1D)
Also, converting between endians and byte-order reversing are common operations. A set of functions available on any computer are the htonl(), ntohl(), htons(), and ntohs() networking functions. Using them requires linking with your platform's networking faciliites. If you don't want to do that, it is easy enough to roll your own, as you did. (Good job!)