Hi,
I'm trying to figure out why the following code works in debug mode, but not in release mode:
// Given m_Game_ID_Nums[0] == 1, m_Game_ID_Nums[1] == 7
// m_Game_ID_Nums[2] == 4, m_Game_ID_Nums[3] == 0
// Note: m_Game_ID_Nums is an integer array
char temp_buffer[8];
sprintf(temp_buffer, "%d%d%d%d", m_Game_ID_Nums[0],
m_Game_ID_Nums[1], m_Game_ID_Nums[2], m_Game_ID_Nums[3]);
temp_buffer, in debug mode, will read "1740", as expected, but in release mode, it reads "1070400". The only way to get the desired result is through the following code
// Given m_Game_ID_Nums[0] == 1, m_Game_ID_Nums[1] == 7
// m_Game_ID_Nums[2] == 4, m_Game_ID_Nums[3] == 0
// Note: m_Game_ID_Nums is an integer array
char temp_buffer[8];
for (int i = 0; i < 4; i++)
{
_itoa(m_Game_ID_Nums, &temp_buffer, 10);
}
temp_buffer[4] = '\0';
In this case, temp_buffer always reads "1740".
Why doesn't sprintf() work properly in release mode? Is there some way I can make it work, no matter what the mode? Or do I have to wiggle around it with _itoa()? It makes the code easier to write and understand, I believe, when using straight-up sprintf().
-Gauvir_Mucca