Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can i use memcmp two compare multibyte characters string?

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.

like image 702
Suri Avatar asked Feb 27 '12 06:02

Suri


People also ask

Is memcmp faster than for loop?

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.

What is the difference between memcmp and Strcmp?

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.

What would be the operation required to compare two string 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.

What does memcmp do?

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.


1 Answers

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.

like image 71
parkovski Avatar answered Sep 30 '22 04:09

parkovski