I am trying to write code to compare two string. In windows i can use strcmp but i want write for multibyte character string so that it compatible to all other platform Can i use memcmp? if no then is there any other API i can use or i need to write my own API.
memcmp is often implemented in assembly to take advantage of a number of architecture-specific features, which can make it much faster than a simple loop in C.
In short: strcmp compares null-terminated C strings. strncmp compares at most N characters of null-terminated C strings. memcmp compares binary byte buffers of N bytes.
The memcmp() built-in function compares the first count bytes of buf1 and buf2. The relation is determined by the sign of the difference between the values of the leftmost first pair of bytes that differ. The values depend on EBCDIC encoding. This function is not locale sensitive.
The memcmp() function compares n bytes of two regions of memory, treating each byte as an unsigned character. It returns an integer less than, equal to, or greater than zero according to whether s1 is lexicographically less than, equal to, or greater than s2.
You have to be careful. I'm not an expert on Unicode/multi byte encodings, but I know that with diacritics sometimes two strings can be considered equal when their bytes are not exactly the same. It's recommended to use pre-tested APIs, because string encodings can get pretty messy.
See the old new thing on case mapping. I can't think of a reference for the diacritics but if I do I'll post it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With