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 that 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."
Last edited on
1
2
// unsigned short usCurrent;
unsigned int usCurrent ; // format "%u" 


Use a std::istringstream instead and you wouldn't have these issues.

1
2
3
std::istringstream stm(scTemp) ;
if( stm >> usCurrent ) { /* do something with usCurrent */ }
else { /* error: does not start with an integer */ }

Thanks !!
Topic archived. No new replies allowed.