From:
man strchr
char *strchr(const char *s, int c);
The strchr() function returns a pointer to the first occurrence of the character c in the string s.
Here "character" means "byte"; these functions do not work with wide or multibyte characters.
Still, if I try to search a multi-byte character like é
(0xC3A9
in UTF-8):
const char str[] = "This string contains é which is a multi-byte character";
char * pos = strchr(str, (int)'é');
printf("%s\n", pos);
printf("0x%X 0x%X\n", pos[-1], pos[0]);
I get the following output:
� which is a multi-byte character
0xFFFFFFC3 0xFFFFFFA9
Despite the warning:
warning: multi-character character constant [-Wmultichar]
So here are my questions:
- What does it means
strchr
doesn't work with multi-byte characters ? (it seems to work, providedint
type is big enough to contains your multi-byte that can be at most 4 bytes) - How to get rid of the warning, i.e. how to safely recover the mult-byte value and store it in an int ?
- Why the prefixes
0xFFFFFF
?