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

Discussion in 'C Programming' started by mimmo, Apr 10, 2004.

  1. mimmo

    mimmo Guest

    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!
     
    mimmo, Apr 10, 2004
    #1
    1. Advertising

  2. "mimmo" <> wrote in message
    news:ZZSdc.119330$...
    > 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
     
    Peter Pichler, Apr 10, 2004
    #2
    1. Advertising

  3. mimmo

    mimmo Guest

    > 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!
     
    mimmo, Apr 10, 2004
    #3
  4. "Peter Pichler" <> writes:
    > "mimmo" <> wrote in message
    > news:ZZSdc.119330$...
    > > 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.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    Schroedinger does Shakespeare: "To be *and* not to be"
     
    Keith Thompson, Apr 10, 2004
    #4
  5. mimmo

    josh Guest

    mimmo <> wrote in
    news:ZZSdc.119330$:

    > 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
     
    josh, Apr 10, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Christopher M. Lusardi
    Replies:
    1
    Views:
    4,094
  2. multi-character constant

    , Nov 21, 2007, in forum: C Programming
    Replies:
    11
    Views:
    2,964
    Willem
    Nov 22, 2007
  3. adibao
    Replies:
    0
    Views:
    1,039
    adibao
    Apr 5, 2009
  4. saurabh29789

    Assign char variable with multi-character constant

    saurabh29789, May 28, 2009, in forum: C Programming
    Replies:
    1
    Views:
    965
    saurabh29789
    May 28, 2009
  5. emeraldsky23

    warning: multi-character character constant error

    emeraldsky23, Jan 15, 2011, in forum: C Programming
    Replies:
    0
    Views:
    1,029
    emeraldsky23
    Jan 15, 2011
Loading...

Share This Page