CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2012
    Posts
    2

    Smile Run-Time Check Failure #2

    Hi all,
    Here is my code:

    char scTemp[8];
    unsigned short usCurrent;
    m_ctEdTemp.GetWindowText(scTemp, 8);
    sscanf(scTemp, "%u", usCurrent);

    Does anyone know what is wrong with this code (I'm sure it's a very basic mistake) ?

    It throws me an error message:
    "Run-Time Check Failure #2 - Stack around the variable 'usCurrent' was corrupted."

    Thanks

  2. #2
    Join Date
    Oct 2012
    Posts
    2

    Re: Run-Time Check Failure #2

    Sorry, the code is:

    char scTemp[8];
    unsigned short usCurrent;
    m_ctEdTemp.GetWindowText(scTemp, 8);
    sscanf(scTemp, "%u", &usCurrent);

  3. #3
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Run-Time Check Failure #2

    Quote Originally Posted by josephhhhh View Post
    Hi all,
    Here is my code:
    Code:
    	char scTemp[8];
    	unsigned short usCurrent;
    	m_ctEdTemp.GetWindowText(scTemp, 8);
    	sscanf(scTemp, "%u", usCurrent);
    Does anyone know what is wrong with this code (I'm sure it's a very basic mistake) ?
    Well, the first thing you did wrong is you ignored using Code tags around code snippets.
    The second one is parameters passed in CWnd::GetWindowText: you must specify the nMaxCount value to be less than the size of your char scTemp[8] array (because one character in it must be the terminated NULL one).

    And finally, you should forget about plain char arrays and sscanf C-runtime function in MFC applications. Use CString class!
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured