1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
/* mblen example */
#include <stdio.h> /* printf */
#include <stdlib.h> /* mblen, mbtowc, wchar_t(C) */
void printbuffer (const char* pt, size_t max)
{
int length;
wchar_t dest;
mblen (NULL, 0); /* reset mblen */
mbtowc (NULL, NULL, 0); /* reset mbtowc */
while (max>0) {
length = mblen (pt, max);
if (length<1) break;
mbtowc(&dest,pt,length);
printf ("[%lc]",dest);
pt+=length; max-=length;
}
}
int main()
{
const char str [] = "test string";
printbuffer (str,sizeof(str));
return 0;
}
|