(ANSI Standard)
#include <stdlib.h> length = mblen(mb,N);
The "mblen" function checks to see whether there is a valid multibyte character (in the current locale) beginning at the location indicated by "mb". The function only checks the first N bytes; therefore, it will only recognize multibyte characters whose length is less than or equal to N.
If "*mb" contains a valid multibyte character, "mblen" returns the number of bytes making up the character. This could be zero, if the string begins with '\0'. If the first N bytes of "mb" do not contain a valid multibyte character from the current locale, "mblen" returns -1.
Note that "mblen" returns a signed integer instead of an (unsigned) "size_t" value, as is usually used for measuring lengths.
If the "mb" argument is a null pointer, "mblen" returns 0 if multibyte characters do not have shift-dependencies, and a non-zero value otherwise.
NOTE: if the current locale has shift dependencies, "mblen" keeps track of the current shift state. Calling "mblen" with a null pointer for "mb" puts "mblen" into the initial shift state. Otherwise, the function will start out in whatever shift state it had at the end of the previous call.
Copyright © 1996, Thinkage Ltd.