-
October 7th, 2012, 04:27 AM
#1
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
-
October 7th, 2012, 04:49 AM
#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);
-
October 7th, 2012, 06:54 AM
#3
Re: Run-Time Check Failure #2
Originally Posted by josephhhhh
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|