I was just playing around with Win32 MessageBox and sprintf... when i noticed that when i try to put a double into an array of chars with sprintf it messes up when i use %d or %i, but it works for ints.
here is what i mean
i tried variations with all the letters in the alphabet and i got weird things like CCCCCCD or cccccd.Code:int x = 1280; int y = 1024; double r = static_cast<double>(x)/static_cast<double>(y); char szBuffer[100]; sprintf(szBuffer, "X: %i, Y: %i, R: %i", x, y, r); OUTPUT: X: 1280, Y: 1024, R: 0 sprintf(szBuffer, "X: %d, Y: %d, R: %d", x, y, r); OUTPUT: X: 1280, Y: 1024, R: 0 sprintf(szBuffer, "X: %d, Y: %d, R: %d", x, y, r); OUTPUT: X: 1280, Y: 1024, R: 1.250000
Can anyone tell me what the %i is for and how its used and the %d and %f and any other ones if there are.
Thanks



LinkBack URL
About LinkBacks


