Date: Thu, 24 May 2007 16:14:21 +0400 From: "Artem Kuchin" <matrix@itlegion.ru> To: "Oliver Fromme" <olli@lurza.secnetix.de>, <freebsd-stable@FreeBSD.ORG> Subject: Re: How to test locale in C? All my tests fail. Message-ID: <031101c79dfd$104c21a0$05000100@Artem> References: <200705241136.l4OBaA9P092420@lurza.secnetix.de>
next in thread | previous in thread | raw e-mail | index | archive | help
Oliver Fromme wrote: > Artem Kuchin wrote: >> I have a very stupid problem. I cannot convert to upper >> or lower case using manually set locale (setlocale(..)). >> >> A very simple program: >> [...] >> printf("IS UPPER ?: %d\n",isupper('?')); >> printf("IS UPPER ?: %d\n",isupper('?')); >> printf("IS LOWER ?: %d\n",islower('?')); > That's a common pitfall. Chars are signed by default on > FreeBSD, and the isupper() etc. function take an int type > argument. That means that characters >= 128 end up as > negative numbers, so they fail all isupper() and islower() > checks, and toupper()/tolower() don't touch them at all. > > The solution is to typecast the constants to unsigned char > explicitly, like this: isupper((unsigned char) '?') etc. > Your program will work fine then. My stupid. I should've noticed that. Thank you very much! Issue closed. -- Regards, Artem
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?031101c79dfd$104c21a0$05000100>