Advertisement

help sprintf

Started by December 07, 2000 07:20 PM
3 comments, last by hellstorm01 24 years, 1 month ago
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
Advertisement
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.
SiCrane,

ive verified that it is sprintf thats not working. its not storing the float into the string just 0.00000

This topic is closed to new replies.

Advertisement