printf and extended chars

D

david

Hi friends, excuse mi poor english, how to right align a string with
printf when extended chars are used?

#include <stdio.h>

int main(void)
{
printf("%10s\n", "mono");
printf("%10s\n", "moño");

return 0;
}

out:
Mono
Moño

both mades 4 chars in the screen but mono is 4 bytes and moño 5 bytes,
how can I fix this
 
L

Luuk

david schreef:
Hi friends, excuse mi poor english, how to right align a string with
printf when extended chars are used?

#include <stdio.h>

int main(void)
{
printf("%10s\n", "mono");
printf("%10s\n", "moño");

return 0;
}

out:
Mono
Moño

both mades 4 chars in the screen but mono is 4 bytes and moño 5 bytes,
how can I fix this

i see something about LC_CTYPE here:
http://www.opengroup.org/onlinepubs/009695399/utilities/printf.html

does this help ?
 
D

david

thanks Luuk!!, works perfect:

setlocale(LC_CTYPE, "");

wprintf(L"%10ls\n", L"mono");
wprintf(L"%10ls\n", L"moño");

out:
mono
moño
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,206
Latest member
SybilSchil

Latest Threads

Top