Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting CString to char...why does this code crash? 1

Status
Not open for further replies.

Aceallways

Programmer
Jan 14, 2006
1
CA
I am trying to convert a C++ console program over to API.

I am almost done, all that is left is the password.

I have an edit box that stores the password, and *need?* to convert it it chars.

Why does this code crash?

unsigned char pass[255];
if(usePass)
{
for(passCs=0;passCs<255;passCs++)
{
if(m_passbox.GetAt(passCs)==0)
{
break;
}
else
{
pass[passCs]=m_passbox.GetAt(passCs);
}
}
}

Thanks in advance for your help.
 
1. Please use the [tt][ignore]
Code:
[/ignore][/tt]
tags when posting code.

2. if(m_passbox.GetAt(passCs)==0)
But if you want the result to also be a proper 'C' string (with a \0), then you also need to store this as well.

Maybe
Code:
unsigned char pass[256];  // one extra
if(usePass)
{
  for(passCs=0;passCs<255;passCs++)
  {
    pass[passCs]=m_passbox.GetAt(passCs);
    if ( pass[passCs] == '\0' ) break;
  }
  pass[passCs] = '\0';  // just in case a v.long pass is entered
}

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top