If you're wanting to print the value of a four-character constant that was passed in as an integer, you have to store the thing somewhere first so you can get its address to pass to printf()
.
What I usually wound up doing was something like:
void PrintFourChar(FILE* of, int fourChar)
{ union
{ int i[2];
char c[8];
} x;
x.i[0] = fourChar;
x.c[4] = 0;
fprintf(of, "%s", x.c);
}
Note that you're only going to get the correct output if the machine that runs this function has the same byte order as the machine that generated the int from the string in the first place.
(Note: Mac OS 9 and earlier made extensive use of these four-character constants. For comparison and tree-search purposes, you just treated them like integers (constant-time copy and compare, better than an arbitrary string), and for display purposes, you'd use a function like the above. They did this because it was easier for a developer to remember that "ALRT" was an alert box resource, "CODE" was a code resource, "STR " was a string, and so forth. They didn't allow control characters, though the OS generally didn't trap for them.)
EDIT: To be completely portable, I should have pulled in <stdint.h>
and used int32_t
in place of int
.