char *w = "Artîsté";
printf("%lu\n", strlen(w));
int z;
for(z=0; z<strlen(w); z++){
//printf("%c", w[z]); //prints as expected
printf("%i: %c\n", z, w[z]);//doesn't print anything
}
If I run this, it fails at the î. How do I print a multibyte char and how do I know when a I've hit a multibyte character?
If your execution environment uses UTF-8 (Linux, for example), your code will work as-is, as long as you set a suitable locale, as in
setlocale(LC_ALL, "en_US.utf9");before calling that printf.demo: http://ideone.com/zFUYM
Otherwise, your best bet is probably to convert to wide string and print that. If you plan on doing something other than I/O with the individual characters of that string, you will have to do it anyway.
As for hitting a multibyte char, the portable way to test is if
mblen()returns a value greater than 1.