How to Fix: 'sprintf' Writing a Terminating Nul Past the End of the Destination
In my C application, I wanted to convert a byte (stored as an unsigned char) into a hexadecimal string. To do so, I wrote the following code:
1char hex[2]; 2unsigned char byte = 10; 3sprintf(hex, "%02X", byte); However, the code produced unreliable results. Moreover, the compiler threw the following warning: …