views:

67

answers:

3

BLUF: In this function, \' prompt the error message but not \?, 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 whats 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.

A: 

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.

James Curran
US-en and FR-fr (to be precise, LCID 0409 and 040C) both are supersets of ASCII, and should function identically here.
MSalters
I`m using FR-ca to be precice, but I do not think that can cause any problems.
Mashuu
A: 

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.

Potatoswatter
Tried it, no change.
Mashuu
A: 

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.

Mashuu