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

M

mimmo

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) {
94 case 'à':
95 t = 'a';
96 break;
97 case 'è': case 'é':
98 t = 'e';
99 break;
100 case 'ì':
101 t = 'i';
102 break;
103 case 'ò':
104 t = 'o';
105 break;
106 case 'ù':
107 t = '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 = '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!
 
P

Peter Pichler

mimmo said:
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) {
94 case 'à':
95 t = 'a';
96 break;
97 case 'è': case 'é':
98 t = 'e';
99 break;
100 case 'ì':
101 t = 'i';
102 break;
103 case 'ò':
104 t = 'o';
105 break;
106 case 'ù':
107 t = '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
 
M

mimmo

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!
 
K

Keith Thompson

Peter Pichler said:
mimmo said:
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 = '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.
 
J

josh

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top