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_AL L,"de_DE.iso885 91");
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.is o88591
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.is o88591 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 ? 3 3538
"gelbeiche" <bo*****@fliege npilz.de> wrote in message
news:m3******** ****@redrat.qua rk.de...
....
I recommend using Unicode, w/o any code pages and locales whatsoever.
Alex
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_AL L,"de_DE.iso885 91"); 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((unsign ed 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.is o88591 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.is o88591 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_AL L, "C");
setlocale(LC_MO NETARY, "de_DE.iso88591 ");
printf ("Locale = %s\n", setlocale(LC_AL L, NULL));
... and I think you will see what is happening.
-- Er*********@sun .com
Eric Sosman <er*********@su n.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_AL L, "C"); setlocale(LC_MO NETARY, "de_DE.iso88591 "); printf ("Locale = %s\n", setlocale(LC_AL L, NULL));
... and I think you will see what is happening.
Yes, I see. Thanks again. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 "license" for more information.
>>> import locale
>>> locale.setlocale(locale.LC_ALL, 'nl_NL')
|
by: JasBascom |
last post by:
if i have
struct crecord{
char record_type;
}
if record_type = 'c';
how do I make record_type toupper?
|
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
void stringToUpper(std::string &str) {
|
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 each letter?
The struct will contain some integers, will tolower/upper affect any
integers?
Also...has anyone written an easy struct to xml converter yet?
|
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 field.Name.Name.ToUpper() in Watch or Command
Window I get the error "error: 'field.Name.Name.ToUpper' does not exist" but
when I print the result using
Debug.WriteLine(field.Name.Name.ToUpper()) it works fine.
| |
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 "toupper" function imposes a further constrait in that the value
passed to it must be representable as a unsigned char. (If C does not
require all character values to be positive, then again, this constrait
too escapes me... )
Let's say we have the...
|
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 main(int argc, char** argv)
|
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;
|
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.
void strUpper (char *myStr) {
int i;
strcpy (*myStr);
for(i=0; myStr; i++) {
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |