bool isInMyCharSet(char ch)
const char* myCharSet="ABCD12349";
return strchr(myCharSet, ch)!=NULL?
The code works for years. Only one day you call this function with '\0'. Char 0 is not part of myCharSet, yet this function returns true.
Senior C programmers often know this, because this behavior is documented.
const char * strchr ( const char * str, int character );
char * strchr ( char * str, int character );
Locate first occurrence of character in string
Returns a pointer to the first occurrence of character in the C string str.
The terminating null-character is considered part of the C string. Therefore, it can also be located to retrieve a pointer to the end of a string.
OK. Fine, but do you know the same behavior exists in CString::Find method. This time, you won't find it mentioned in the document.
Now you may attempt to change the code to
for(int i=0; i
if (myCharSet[i]==ch) return true;
Wrong again. sizeof operator still counts the terminating NUL character.