Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(s)printf width and utf-8

Status
Not open for further replies.

monkhandle

Programmer
Oct 21, 2007
32
0
0
SI
Is this proper behaviour of printf family functions:

Code:
printf("'%4s'","€");

output:

Code:
' €'

Shouldn't output be
Code:
'   €'
? It seems as if all bytes (3 for euro symbol) were counted as visible field width.
 
The Euro symbol isn't one of the 127 ASCII characters. It is a multibyte character. You have a choice of using mulitbyte or wide characters. With wide characters, it would be
Code:
wsprintf (L"%4s", L"€");
 
That doesn't work, but:

Code:
wprintf(L"'%4S'",L"€");

outputs:

Code:
'   EUR'

:D

Probably locales are not set properly. But still, why € symbol is output correctly with printf then ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top