I’m reading in two 32 bit registers and trying to put it inside a string buffer using the following:
sprintf (buffer, "%s-%s", ((char*)(in32(REGISTER1))) , (char*)(in32(REGISTER2)));
Can the hex value read in from the registers not be typecast as a pointer to a char and be printed into the buffer as above?
As craig65535 implies in a comment above, the problem is most likely with this phrase:
I doubt that you’re reading in a hex value; rather, you’re reading in an integer. If you want to store a hex representation of that integer in a string, you’d use the
%Xformat specifier:(The
8means “use a width of eight characters”; the0means “left-pad with zeroes if the value is such that the width is less than eight”.)The only way you could validly cast to
char *is if the integer value in the register is actually a pointer to some memory location where you’ve stored a string; but that is clearly not the case here.