(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: Since this version of C only recognizes single byte characters, all non-null strings start with a valid character whose length is 1.
Copyright © 1996, Thinkage Ltd.