Julio Batista Julio Batista - 3 months ago 13
C Question

What exactly does '%Id' mean? (uppercase I, lowercase d)

I'm asking about

%Id
, not
%ld
.

Can anyone please explain to me what does "I" exactly do:


I
For decimal integer conversion (
i
,
d
,
u
) the output uses the
locale's alternative output digits, if any. For
example, since glibc 2.2.3 this will give Arabic-Indic digits in the Persian (
"fa_IR"
) locale.


As an example:

printf("%Id",1);


In other words what is the difference between
%d
and
%Id
?

can anyone please explain it with simple words and simple example stating the difference ?

Answer

printf format option I is a glibC extension to select a locale representation for numbers. It is not defined by the C Standard and should not be used in portable code.

If the locale is properly selected and supported by your C library, calling printf("%Id", 1); might produce a string encoding the Unicode code point U+0661 ١ that is the representation of the digit one in arabic.

See http://www.fileformat.info/info/unicode/char/0661/index.htm

Conversely, printf("%d", 1); always prints 1, the western representation of number one.

To make matters even more confusing, 1 is called an arabic numeral, as opposed to roman numeral I... unrelated to the I in %Id.