Home > Software engineering >  An array of strings, to solve.
An array of strings, to solve.

Time:10-05

Recently in the MFC to do a file encryption software, using GetDlgItemText function, will the nMaxCount parameter is set to 9, when you need to control the number of input in the edit box key, use strlen identify me character number, want to use eight characters as encryption keys,, but I was in a controlled,
Else if (strlen (ch_Key) & gt;=9)
{
MessageBox (" the key for long! Input again!!!!!!!!!! ");
return;
}

This code seems doesn't work, as long as the input number is more than eight characters, will continue, will not return, then I wrote a test code, as shown in figure,
Found the result is shown in figure,
I don't know why ah, I'll find an array of strings, also didn't see anything useful, so ask you, thank you,

CodePudding user response:

You provide two pieces of code, there is no link?

In addition, the char [] array, the scanf is, should not be & amp; STR, should be the scanf (" % s ", STR), because STR is itself a pointer (array),

CodePudding user response:

Debugging see strlen return many, string to look at

CodePudding user response:

Actually computer after each byte of physical memory that are read/write, never because of the so-called new, delete or malloc, free and is created and destroyed, the difference only lies in the operating system memory management module can find when you read and write and whether to take appropriate action, and the granularity of the operating system manages memory rather than bytes page, a page is usually 4 KB,

CodePudding user response:

The scanf (" % 3 s ", STR);

CodePudding user response:

After judgment length exceeds the limit, to remove the extra characters in a string, or only a hint, and can't do the actual limit

CodePudding user response:

The scanf can't address-of operator & amp;

CodePudding user response:

The code below notice array overflow problem,
  • Related