The Open Source Swiss Army Knife

/code/c/unix_c/
/code/c/unix_c/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /code   /c   /unix_c 
Permalink: checklocale2.c
Title: add
article options : please login   |  raw source view  

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

int
main(int argc, char** argv)
{
	int		i, n, j = 0, k = 0;
	char   *locale1, *locale2;

	locale1 = argv[1];
	locale2 = argv[2];
	n = atoi(argv[3]);

	/* not ifdef'd, so that without USE_LOC we only test locale1 */
	if (setlocale(LC_COLLATE, locale1) == NULL)
	{
		printf("setlocale(LC_COLLATE, %s) failed\n", locale1);
		exit(1);
	}
	if (setlocale(LC_CTYPE, locale1) == NULL)
	{
		printf("setlocale(LC_CTYPE, %s) failed\n", locale1);
		exit(1);
	}

	for (i = 0; i < n; i++)
	{
#ifdef USE_LOC
		if (setlocale(LC_COLLATE, locale1) == NULL)
		{
			printf("setlocale(LC_COLLATE, %s) failed\n", locale1);
			exit(1);
		}
		if (setlocale(LC_CTYPE, locale1) == NULL)
		{
			printf("setlocale(LC_CTYPE, %s) failed\n", locale1);
			exit(1);
		}
#endif
		j = strcoll("foobarbaz", "foo bar bath");
#ifdef USE_LOC
		if (setlocale(LC_COLLATE, locale2) == NULL)
		{
			printf("setlocale(LC_COLLATE, %s) failed\n", locale2);
			exit(1);
		}
		if (setlocale(LC_CTYPE, locale2) == NULL)
		{
			printf("setlocale(LC_CTYPE, %s) failed\n", locale2);
			exit(1);
		}
#endif
		k = strcoll("foobarbaz", "foo bar bath");
	}

	printf("in %s strcoll gives %d\n", locale1, j);
#ifdef USE_LOC
	printf("in %s strcoll gives %d\n", locale2, k);
#endif

	return 0;
}


Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top