Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > warning: multi-character character constant...help me!

Reply
Thread Tools

warning: multi-character character constant...help me!

 
 
mimmo
Guest
Posts: n/a
 
      04-10-2004
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!
 
Reply With Quote
 
 
 
 
Peter Pichler
Guest
Posts: n/a
 
      04-10-2004
"mimmo" <(E-Mail Removed)> wrote in message
news:ZZSdc.119330$(E-Mail Removed).. .
> 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


 
Reply With Quote
 
 
 
 
mimmo
Guest
Posts: n/a
 
      04-10-2004
> 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!

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      04-10-2004
"Peter Pichler" <(E-Mail Removed)> writes:
> "mimmo" <(E-Mail Removed)> wrote in message
> news:ZZSdc.119330$(E-Mail Removed).. .
> > 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) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
 
Reply With Quote
 
josh
Guest
Posts: n/a
 
      04-10-2004
mimmo <(E-Mail Removed)> wrote in
news:ZZSdc.119330$(E-Mail Removed):

> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
remove the last character or the newline character? Daniel Mark Python 6 09-28-2006 02:40 PM
character encoding +missing character sequence raavi Java 2 03-02-2006 05:01 AM
getting the character code of a character in a string Velvet ASP .Net 9 01-19-2006 09:27 PM
Character reference "&#c" is an invalid XML character cgbusch XML 6 09-02-2003 07:04 PM
question: reading character for character from stdin KwikRick Python 1 08-22-2003 05:56 PM



Advertisments