i18n programming question
I write the following code to test the mbtowc function:
#include <stdlib.h>
#include <locale.h>
int main(int argc,char **argv)
{
wchar_t pwc;
int consumed;
setlocale(LC_ALL,"zh_TW.Big5");
if(argc > 1)
{
int length=strlen(argv[1]);
int i=0;
while(consumed=mbtowc(&pwc,argv[1]+i,length-i)>0)
{
printf("Consumed Byte %d\n",consumed);
printf("Character : %lc\n",pwc);
i+=consumed;
}
}
}
Here is the output:
hingwah@hingwah:~/programming/i18n$./testcharacter 意非凡BBS
Consumed Byte 1
Character : 意
Consumed Byte 1
Character : N
Consumed Byte 1
Character : 非
Consumed Byte 1
Character : D
Consumed Byte 1
Character : 凡
Consumed Byte 1
Character : Z
Consumed Byte 1
Character : B
Consumed Byte 1
Character : B
Consumed Byte 1
Character : S
And I want to ask isn't the mbtowc function should return 2 as it consume 2 byte
to construct the chinese character?
Reply to: