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
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);
Re: Run-Time Check Failure #2
Quote:
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!