Home » C programs

localeconv() function of locale.h in C

In this article we are going to learn about the localeconv() function of locale.h header file in C programming language and use it to returns a pointer to a structure that contains current locale information.
Submitted by Abhishek Sharma, on April 20, 2018

If you want to make your application which works according to the location of the user, then this article is for you.

First, make a structure pointer which will point to structure object of lconv. Then, set your locality by calling setlocale(category, string).

In most cases, using LC_ALL as the category would be enough and passing the empty string for the second parameter will set everything as default.

Third thing is to get the address or the reference of the object and store it inside out locale pointer variable.

Finally, we have this awesome structural object ready to be used. You can get many things out of it, here is the list.

Reference: http://pubs.opengroup.org/onlinepubs/009695399/functions/setlocale.html

locale.h - localeconv() function Example in C



#include <stdio.h>
#include <locale.h>

int main()
{
	//defining the type of variables
	struct lconv *a;

	//Setting the locale variable to the environment
	setlocale (LC_ALL, "");

	//Retrieving the pointer position to current locale
	a = localeconv();

	//Displaying the message with values
	printf("Symbol to separate the values in thousand: %s\n\n", a->thousands_sep);

	printf("Symbol to define the values in currency: %s\n\n", a->currency_symbol);

	return 0;
}

Output

locale.h - localeconv() in c language



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.