help sprintf
i have a real problem. Im doing a billing program that retrieves text from edit boxes(in win32 that is) and converts the strings into a floating point value, this part goes without a hitch. When I try to set the float back into the edit box when a billing record is opened only the first one i try works, ie i do:
//the rate will set but nothing else manages to work
SetEditFloat(hDlg, IDC_RATE,"%.2f", BillInfo.Rate);
SetEditFloat(hDlg, IDC_MILEAGE,"%.2f", BillInfo.Mileage);
SetEditFloat(hDlg, IDC_DIS,"%.2f", BillInfo.Discount);
SetEditFloat(hDlg, IDC_TOTAL,"%.2f", BillInfo.Total);
however if i switch it aroung a bit like
//here only the mileage manages to work and be set
SetEditFloat(hDlg, IDC_MILEAGE,"%.2f", BillInfo.Mileage);
SetEditFloat(hDlg, IDC_RATE,"%.2f", BillInfo.Rate);
SetEditFloat(hDlg, IDC_DIS,"%.2f", BillInfo.Discount);
SetEditFloat(hDlg, IDC_TOTAL,"%.2f", BillInfo.Total);
get the idea now?
here is the code for SetEditFloat
void SetEditFloat(HWND hwndparent, unsigned long control, const char* format, float fval)
{
char string[7];
sprintf(string, format, fval);
SetDlgItemText(hwndparent, control, string);
}
So my question is WTF is only allowing the first edit box i specify be filled with the floating point value and not the others?
Thanks to any gamedever that can help me out!
HellStorm
Hmm, looks like it should work. Is your ''string'' long enough? If it is too short, you will trash the stack and cause strange things to happen.
Other than that...
Tim
Other than that...
Tim
Have you checked exactly which function is failing? i.e. Do you check the return value of SetDlgItemText? Or stepped through and verified that the buffer contains the right string before the SetDlgItemText call?
yea Ive tried lengthening the string up to 255 characters in length but still only the first field is set. Strangest thing i''ve ever seen. Without this working my program is absolutely useless.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement