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 30 31 32
|
/* mbrlen example */
#include <stdio.h>
#include <string.h>
#include <wchar.h>
void splitmb (const char* pt, size_t max)
{
size_t length;
wchar_t dest;
mbstate_t mbs;
int i;
mbrlen (NULL,0,&mbs); /* initialize state */
while (max>0) {
length = mbrlen (pt, max, &mbs);
if ((length==0)||(length>max)) break;
putchar ('[');
for (i=0; i<length; ++i) putchar (*pt++);
putchar (']');
max-=length;
}
}
int main()
{
const char str [] = "test string";
splitmb (str,sizeof(str));
return 0;
}
|