Invalid character string partly recognized? c++
BLUF: In this function, \' prompt the error message but no开发者_如何学Pythont \?, Why?
char key[] = "\a\b\f\n\r\t\v\\\'\"#%&*;:<>\?/{|}~";
if (strpbrk(*local_str, key) != NULL )
{
vico_param_out->out_valid = false;
AfxMessageBox("L'identifiant de numérisation est invalide. Vous avez saisi des caractères qui ne peuvent pas faire partie d'un nom de fichier windows (\"#%&*;:<>\?\\/{|}~). Veuillez faire les corrections nécessaires.");
}
This snippet of code is supposed to check if one of the invalid caracters is in the input string (*local_str). Works well with some of them, but if some characters like \? are in *local_str. it accepts it and do not show the error message. I dont understand what
s happening.
Example: ABC is valid
AB' is not valid, prompt mesage for correction AB? is not valid but falls through A'? is not valid but also falls through.Please help. I am indepted to this community.
EDIT: Problem solved. I would seem that this function works but another process which I was unaware of was catching the keys in local_str as shortcuts before the call to my function, hence the weird behavior. I moved my function to be evaluated when each keystroke is inputed.
My deepest apologies for annoyance. Thanks you everyone.
Running this code, all three invalid string produce the error message.
int _tmain(int argc, _TCHAR* argv[])
{
char local_str[] = "A'?";
char key[] = "\a \b \f \n \r \t \v \\ \? \' \" \" # % & * ; : < > \? \\ \' / { | } ~ ";
if (strpbrk(local_str, key) != NULL )
{
cout << ("L'identifiant ......");
}
return 0;
}
My only guess is that there may be some mismatch between US-en and FR-fr character sets.
A simple program calling strpbrk
with your given input does not produce the problem. Try changing to char const key[]
to see if key
is getting modified between uses.
My apologies. The code is working fine afterall. Another process was intercepting local_str before my code was executed and throw a silent exception and skipped my function all together.
I moved my code to be executed before that said process and it should be fixed tomorrow morning.
精彩评论