473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

toupper and locale

I have a question regarding the following
small C program.

#include <locale.h>

int main()
{
char* loc = 0;
char before,after;
int i;
loc = setlocale(LC_ALL,"de_DE.iso88591");
printf("locale:%s\n", loc);
before = 'ä';
printf("decimal value:%d \n",before);
printf("hex value:%x \n",before);
printf("char value:%c \n",before);
i = toupper(before);
printf("i=%i\n",i);
after = (char) i;
printf("decimal value:%d \n",after);
printf("hex value:%x \n",after);
printf("after=%c\n",after);
}

At Linux the output of the program looks ok.
It converts the German umlaut 'ä' to the upper
'Ä'.
output at linux:
locale:de_DE.iso88591
decimal value:-28
hex value:ffffffe4
char value:ä
i=196
decimal value:-60
hex value:ffffffc4
after=Ä

But now look at the output at HPUX (compiled
with HPUXs C-compiler cc):
locale:de_DE.iso88591 de_DE.iso88591 de_DE.iso88591 de_DE.iso88591 de_DE.iso88591 de_DE.iso88591
decimal value:-28
hex value:ffffffe4
char value:ä
i=0
decimal value:0
hex value:0
after=

The locale is multiple times printed
and the character is not converted properly.

When I call `locale -a` at HPUX the de_DE.iso88591
locale is listed.

What is the reason for this misbehaviour ?

Nov 15 '05 #1
3 3506
"gelbeiche" <bo*****@fliegenpilz.de> wrote in message
news:m3************@redrat.quark.de...
....
I recommend using Unicode, w/o any code pages and locales whatsoever.

Alex
Nov 15 '05 #2


gelbeiche wrote:
I have a question regarding the following
small C program.

#include <locale.h>

int main()
{
char* loc = 0;
char before,after;
int i;
loc = setlocale(LC_ALL,"de_DE.iso88591");
printf("locale:%s\n", loc);
before = 'ä';
printf("decimal value:%d \n",before);
printf("hex value:%x \n",before);
printf("char value:%c \n",before);
i = toupper(before);
i = toupper((unsigned char)before);
printf("i=%i\n",i);
after = (char) i;
printf("decimal value:%d \n",after);
printf("hex value:%x \n",after);
printf("after=%c\n",after);
}

At Linux the output of the program looks ok.
It converts the German umlaut 'ä' to the upper
'Ä'.
output at linux:
locale:de_DE.iso88591
decimal value:-28
hex value:ffffffe4
char value:ä
i=196
decimal value:-60
hex value:ffffffc4
after=Ä

But now look at the output at HPUX (compiled
with HPUXs C-compiler cc):
locale:de_DE.iso88591 de_DE.iso88591 de_DE.iso88591 de_DE.iso88591 de_DE.iso88591 de_DE.iso88591
decimal value:-28
hex value:ffffffe4
char value:ä
i=0
decimal value:0
hex value:0
after=

The locale is multiple times printed
and the character is not converted properly.

When I call `locale -a` at HPUX the de_DE.iso88591
locale is listed.

What is the reason for this misbehaviour ?


The character conversion is incorrect because the
argument to toupper() is incorrect. The argument to a
<ctype.h> function must be an `unsigned char' value or
the negative value EOF; the functions are not defined
for any other argument values.

The locale string shows that the current locale is
made up of several components (LC_COLLATE, LC_CTYPE, ...),
and each component can be set independently to a different
set of conventions. The Linux library seems to recognize
the special case that all components are set the same way;
HP-UX appears to list each component separately. Try this
experiment:

setlocale(LC_ALL, "C");
setlocale(LC_MONETARY, "de_DE.iso88591");
printf ("Locale = %s\n", setlocale(LC_ALL, NULL));

... and I think you will see what is happening.

--
Er*********@sun.com

Nov 15 '05 #3
Eric Sosman <er*********@sun.com> writes:
The character conversion is incorrect because the
argument to toupper() is incorrect. The argument to a
<ctype.h> function must be an `unsigned char' value or
the negative value EOF; the functions are not defined
for any other argument values.
Thanks for your explanation. The function works now.
The locale string shows that the current locale is
made up of several components (LC_COLLATE, LC_CTYPE, ...),
and each component can be set independently to a different
set of conventions. The Linux library seems to recognize
the special case that all components are set the same way;
HP-UX appears to list each component separately. Try this
experiment:

setlocale(LC_ALL, "C");
setlocale(LC_MONETARY, "de_DE.iso88591");
printf ("Locale = %s\n", setlocale(LC_ALL, NULL));

... and I think you will see what is happening.


Yes, I see. Thanks again.
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ksenia Marasanova | last post by:
Hi, I have some problems with locale module. On my workstation, changing locale doesn't have effect: Python 2.3 (#1, Sep 13 2003, 00:49:11) on darwin Type "help", "copyright", "credits" or...
2
by: JasBascom | last post by:
if i have struct crecord{ char record_type; } if record_type = 'c'; how do I make record_type toupper?
7
by: Duane | last post by:
Aside from the pitfalls of using this function, according to the standard, what is the correct way to call it? #include <string> #include <locale> // seems to work with BCC5.6/STLPort...
18
by: didgerman | last post by:
Chaps, I need to properly format the case of a struct. Can I just hit it with tolower, and then 'while (string ==' ') pos++; string=toupper(string); to add in the higher case for the start of...
0
by: Shrinivas Reddy | last post by:
Hi, I am using the ToUpper() function in an FXCop rule which checks whether a boolean variable has "is" or "has" as the prefix. The ToUpper() function does not work. When I put the expression...
48
by: Frederick Gotham | last post by:
The "toupper" function takes an int as an argument. That's not too irrational given that a character literal is of type "int" in C. (Although why it isn't of type "char" escapes me... ) The...
2
by: cris | last post by:
Hi, I got trouble when I try to change the locale used in a program foo.cc // ----------------- begin #include <iostream> #include <locale> #include <exception> using namespace std; int...
4
by: sandy | last post by:
I am trying to upper case a string, so I have this method: string FileSystem::toupper(string S) { for (int i=0; i<S.length(); ++i) { S=toupper(S); } return S;
16
by: gaga | last post by:
my function should accept a pointer to a string as its argument. and it should convert each charater to an uppercase letter. I know what i need to do, its just my syntax is all out of whack. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.