- fseek(outf, 0, 0L);
- fwrite(deck, sizeof (DECK), 2, outf);
- fwrite(CC_D.offsets, sizeof (long), CC_D.num_cards, outf);
- fwrite(CH_D.offsets, sizeof (long), CH_D.num_cards, outf);
+ fseek(outf, 0, SEEK_SET);
+
+ /* number of community chest cards first... */
+ nc = h2nl(CC_D.num_cards);
+ fwrite(&nc, sizeof(nc), 1, outf);
+ /* ... then number of chance cards. */
+ nc = h2nl(CH_D.num_cards);
+ fwrite(&nc, sizeof(nc), 1, outf);
+
+ /* dump offsets in big-endian byte order */
+ for (i = 0; i < CC_D.num_cards; i++)
+ fwrite_be_offt(CC_D.offsets[i], outf);
+ for (i = 0; i < CH_D.num_cards; i++)
+ fwrite_be_offt(CH_D.offsets[i], outf);
+
+ fflush(outf);
+ if (ferror(outf)) {
+ perror(outfile);
+ exit(1);
+ }