tags:

views:

147

answers:

1

This post originated from http://stackoverflow.com/questions/1492918/how-do-you-get-what-kind-of-encoding-your-system-uses-in-c-c

I tried using

nl_langinfo(CODESET)

but I got ANSI_X3.4-1968 instead of UTF-8 (which is what I get when typing: locale charmap). Am I using nl_langinfo() wrong? How should I use it?

+1  A: 

You need to first call

setlocale(LC_ALL, "");

nl_langinfo always gives information about the current locale.

Martin v. Löwis
To expand on that, a C program always starts with the current locale as the "C" locale - the snippet in this answer is what you use to replace that with the system default locale.
caf
ok thx it works now