Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   warning: multi-character character constant...help me! (http://www.velocityreviews.com/forums/t317807-warning-multi-character-character-constant-help-me.html)

mimmo 04-10-2004 01:51 PM

warning: multi-character character constant...help me!
 
Hi! I should convert the accented letters of a string in the correspondent
letters not accented. But when I compile with -Wall it give me:

warning: multi-character character constant

Do the problem is the charset? How I can avoid this warning? But the worst
thing isn't the warning, but that the program doesn't work! The program
execute all other operations well, but it don't print the converted
letters: for example, in the string "licia colò" (with finally o accented),
instead giving in stdout "licia colo" (without finally o accented), how
should be, print "licia col ", with two spaces.
The code is this:

<CODE>

93 switch(s[i]) {
94 case '*':
95 t[i] = 'a';
96 break;
97 case 'è': case 'é':
98 t[i] = 'e';
99 break;
100 case 'ì':
101 t[i] = 'i';
102 break;
103 case 'ò':
104 t[i] = 'o';
105 break;
106 case 'ù':
107 t[i] = 'u';
108 break;
109 default:
110 break;
111 }

</CODE>

Between the apexes there are the accented letters. I try also with sprintf(t
+ i, "a") instead of t[i] = 'a', but it's the same thing. If instead of
accented letters I try to insert the unaccented letters, all works good.
The output of the gcc is this:

<OUTPUT>

[mimmo@localhost mimmo]$ gcc -Wall p.c -o p
p.c:94:38: warning: multi-character character constant
p.c:97:38: warning: multi-character character constant
p.c:97:49: warning: multi-character character constant
p.c:100:38: warning: multi-character character constant
p.c:103:38: warning: multi-character character constant
p.c:106:38: warning: multi-character character constant
[mimmo@localhost mimmo]$

</OUTPUT>

I hope anyone can give me an help, before than I drop the computer out
window!

Peter Pichler 04-10-2004 02:05 PM

Re: warning: multi-character character constant...help me!
 
"mimmo" <-webmaster-@libero.it> wrote in message
news:ZZSdc.119330$Kc3.3914335@twister2.libero.it.. .
> Hi! I should convert the accented letters of a string in the correspondent
> letters not accented. But when I compile with -Wall it give me:
>
> warning: multi-character character constant
>
> Do the problem is the charset? How I can avoid this warning? But the worst
> thing isn't the warning, but that the program doesn't work! The program
> execute all other operations well, but it don't print the converted
> letters: for example, in the string "licia col" (with finally o

accented),
> instead giving in stdout "licia colo" (without finally o accented), how
> should be, print "licia col ", with two spaces.
> The code is this:
>
> <CODE>
>
> 93 switch(s[i]) {
> 94 case '':
> 95 t[i] = 'a';
> 96 break;
> 97 case '': case '':
> 98 t[i] = 'e';
> 99 break;
> 100 case '':
> 101 t[i] = 'i';
> 102 break;
> 103 case '':
> 104 t[i] = 'o';
> 105 break;
> 106 case '':
> 107 t[i] = 'u';
> 108 break;
> 109 default:
> 110 break;
> 111 }
>
> </CODE>


Your compiler apparently doesn't like the accented characters. If you are
writing your translation for a specific codepage, you can use the relevant
character codes (e.g. 0xa0 for a acute). You could also improve your code by
using translation tables instead of a hardcoded switch, that way you have
your way open for multiple codepages.

Peter



mimmo 04-10-2004 02:20 PM

Re: warning: multi-character character constant...help me!
 
> Your compiler apparently doesn't like the accented characters.

My compiler is gcc 3.3.2, how is possible the problem is the compiler?
Anyway I try to use the relevant character codes. Thank you!


Keith Thompson 04-10-2004 07:49 PM

Re: warning: multi-character character constant...help me!
 
"Peter Pichler" <pichlo7@pobox.sk> writes:
> "mimmo" <-webmaster-@libero.it> wrote in message
> news:ZZSdc.119330$Kc3.3914335@twister2.libero.it.. .
> > Hi! I should convert the accented letters of a string in the correspondent
> > letters not accented. But when I compile with -Wall it give me:
> >
> > warning: multi-character character constant

[...]
> > 106 case '':
> > 107 t[i] = 'u';
> > 108 break;

[...]
> Your compiler apparently doesn't like the accented characters. If you are
> writing your translation for a specific codepage, you can use the relevant
> character codes (e.g. 0xa0 for a acute). You could also improve your code by
> using translation tables instead of a hardcoded switch, that way you have
> your way open for multiple codepages.


The fact that the message warns about a "multi-character character
constant" (the kind of warning I'd expect for something like 'xy'), I
don't think it's *just* a matter of not liking accented characters.
My best guess is that you're using a UTF-8 encoding, which encodes
Unicode characters in multiple bytes. Your text editor is correctly
interpreting the UTF-8 sequences and displaying them for you as
accented characters, but gcc apparently doesn't handle them.

gcc may have an option to accept UTF-8 in source files; check the gcc
documentation. Or you may be able to translate your UTF-8 source
files to something like ISO-8859-1, which represents each character as
a single byte (but doesn't handle the full range of Unicode).

If you can't find the details in your documentation, try a newsgroup
specific to your operating system.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"

josh 04-10-2004 08:15 PM

Re: warning: multi-character character constant...help me!
 
mimmo <-webmaster-@libero.it> wrote in
news:ZZSdc.119330$Kc3.3914335@twister2.libero.it:

> Hi! I should convert the accented letters of a string in the
> correspondent letters not accented. But when I compile with -Wall it
> give me:
>
> warning: multi-character character constant
>
> Do the problem is the charset? How I can avoid this warning? But the
> worst thing isn't the warning, but that the program doesn't work! The
> program execute all other operations well, but it don't print the
> converted letters: for example, in the string "licia colò" (with
> finally o accented), instead giving in stdout "licia colo" (without
> finally o accented), how should be, print "licia col ", with two
> spaces. The code is this:


You're using a multi-byte character set, possibly UTF-8. The accented
characters are occupying more than a single char each. See if you have
library functions for dealing with UTF-8 characters and rethink your
algorithm. (you can't scan one char at a time, you need to go by code
point)

The warning is because you are putting more than a single char between the
''s. The interpretation of this depends on endianness. Worse yet, since
the resulting constant won't fit in a single char, you'll never properly
match the input character.

String processing is a real pain...

-josh




All times are GMT. The time now is 05:17 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.