Printing thousands-separated integers in Windows using C

The question is pretty clear, I suppose. I use printf and friends (snprintf etc.) to display some memory statistics that are in the range of millions or hundreds of thousands. Reading a number formatted as "1,523,556" is much simpler than "1523556" for my lazy way of thinking.

I tried to set the locale and use the apostrophe flag in front of the format specifier (% 'd and%' llu), but the apostrophe seems to be the standard from SUS, so it may not work for me under Windows anyway.

Is there an API for Windows for this? I work with Pelles C and programming in direct ANSI C99.

** EDIT **

After reading the answers and related MSDN pages, I understand why .NET is the preferred programming for Windows. It smooths out a huge amount of API work.

+1
source share
2 answers

The Win32 API provides a function that will format a number with a thousand groupings (or any grouping is suitable for the specified locale): GetNumberFormat()( http://msdn.microsoft.com/en-us/library/dd318110.aspx ).

Unfortunately, this is a rather painful API to use - not as simple as an apostrophe format specifier in SUS (on the other hand, you get more flexibility in exchange for complexity)

+2
source

GetNumberFormatEx ( Windows Vista ). LOCALE_NAME_USER_DEFAULT , , .

+1

Source: https://habr.com/ru/post/1531178/


All Articles