Click here to Skip to main content
15,920,896 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Converting text to float (MFC) Pin
Member 166473326-Jan-05 6:56
Member 166473326-Jan-05 6:56 
GeneralRe: Converting text to float (MFC) Pin
David Crow26-Jan-05 7:00
David Crow26-Jan-05 7:00 
GeneralRe: Converting text to float (MFC) Pin
Member 166473326-Jan-05 7:05
Member 166473326-Jan-05 7:05 
GeneralRe: Converting text to float (MFC) Pin
David Crow26-Jan-05 7:13
David Crow26-Jan-05 7:13 
GeneralRe: Converting text to float (MFC) Pin
Member 166473326-Jan-05 7:16
Member 166473326-Jan-05 7:16 
GeneralRe: Converting text to float (MFC) Pin
Bob Ciora26-Jan-05 7:27
Bob Ciora26-Jan-05 7:27 
GeneralRe: Converting text to float (MFC) Pin
Member 166473326-Jan-05 7:49
Member 166473326-Jan-05 7:49 
GeneralRe: Converting text to float (MFC) Pin
Bob Ciora26-Jan-05 8:03
Bob Ciora26-Jan-05 8:03 
Try putting a breakpoint at the start of the function, then single step through it (with F10). Use your Watch window to watch the values of tmp, txtEdit, boxval, and d as each line is executed. Validate the values at each step, and make sure you see the following:

  (code)                                 (output)

  CString tmp, txtEdit="82.45";          // tmp = "", txtEdit = "82.45"
  float boxval;                          // boxval is undefined at this point

  char *txt = (char *)(LPCTSTR)txtEdit;  // txt = "82.45"
  sscanf(txt, "%f", &boxval);            // boxval = 82.45
  double d = atof(txt);                  // d = 82.45

  tmp.Format(_T("atof is %f", d);        // what is tmp here?
// AfxMessageBox(tmp);                   // don't need this for testing
  tmp.Format(_T("sscanf is %f", boxval); // what is tmp here?
//  AfxMessageBox(tmp);                  // single step is your friend!


Definitely a stumper, but it's definitely worth single stepping.

As a side note on programming practice, you should do the following:
const char * txt = (LPCTSTR)txtEdit; instead of your original char * txt = (char *)(LPCTSTR)txtEdit;. You may run into unintended consequences if you force a const to a non-const. It's not hurting you here, but it could bite you in bad places. I'm curious to know if you get a compiler warning from your original statement.



Bob Ciora
GeneralRe: Converting text to float (MFC) Pin
Member 166473326-Jan-05 8:26
Member 166473326-Jan-05 8:26 
GeneralRe: Converting text to float (MFC) Pin
Member 166473326-Jan-05 8:28
Member 166473326-Jan-05 8:28 
GeneralRe: Converting text to float (MFC) Pin
Bob Ciora26-Jan-05 8:59
Bob Ciora26-Jan-05 8:59 
GeneralRe: Converting text to float (MFC) Pin
Member 166473326-Jan-05 9:05
Member 166473326-Jan-05 9:05 
GeneralRe: Converting text to float (MFC) Pin
Bob Ciora26-Jan-05 9:21
Bob Ciora26-Jan-05 9:21 
GeneralRe: Converting text to float (MFC) Pin
Member 166473326-Jan-05 9:31
Member 166473326-Jan-05 9:31 
GeneralRe: Converting text to float (MFC) Pin
David Crow26-Jan-05 9:59
David Crow26-Jan-05 9:59 
GeneralRe: Converting text to float (MFC) Pin
Member 166473326-Jan-05 10:06
Member 166473326-Jan-05 10:06 
GeneralRe: Converting text to float (MFC) Pin
David Crow26-Jan-05 10:11
David Crow26-Jan-05 10:11 
GeneralRe: Converting text to float (MFC) Pin
Bob Ciora26-Jan-05 10:43
Bob Ciora26-Jan-05 10:43 
GeneralRe: Converting text to float (MFC) Pin
David Crow26-Jan-05 8:53
David Crow26-Jan-05 8:53 
GeneralRe: Converting text to float (MFC) Pin
Tom Wright26-Jan-05 8:45
Tom Wright26-Jan-05 8:45 
GeneralRe: Converting text to float (MFC) Pin
Member 166473326-Jan-05 8:53
Member 166473326-Jan-05 8:53 
GeneralCDialog Question Pin
Anonymous26-Jan-05 5:53
Anonymous26-Jan-05 5:53 
GeneralRe: CDialog Question Pin
David Crow26-Jan-05 5:59
David Crow26-Jan-05 5:59 
GeneralRe: CDialog Question Pin
Anonymous26-Jan-05 6:26
Anonymous26-Jan-05 6:26 
GeneralRe: CDialog Question Pin
David Crow26-Jan-05 6:44
David Crow26-Jan-05 6:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.