printf("%ls")

Discussion in 'C Programming' started by Ioannis Vranos, Feb 28, 2008.

  1. Is printf("%ls") for printing wchar_t strings defined in C90, or it was
    added in C95?
     
    Ioannis Vranos, Feb 28, 2008
    #1
    1. Advertising

  2. In article <fq7evp$11g8$>,
    Ioannis Vranos <> wrote:
    >Is printf("%ls") for printing wchar_t strings defined in C90, or it was
    >added in C95?


    It was not present in C89 -- which has a specific footnote for %s
    indicating that no special provision is made for multibyte characters.
    --
    "All human knowledge takes the form of interpretation."
    -- Walter Benjamin
     
    Walter Roberson, Feb 28, 2008
    #2
    1. Advertising

  3. Walter Roberson wrote:
    > In article <fq7evp$11g8$>,
    > Ioannis Vranos <> wrote:
    >> Is printf("%ls") for printing wchar_t strings defined in C90, or it was
    >> added in C95?

    >
    > It was not present in C89 -- which has a specific footnote for %s
    > indicating that no special provision is made for multibyte characters.



    So what is the need of printf("%ls") in C95 since we got wprintf()?

    Wan't there any possibility to print wide-character strings or wchar_ts
    under C90 directly?
     
    Ioannis Vranos, Feb 28, 2008
    #3
  4. Ioannis Vranos

    Micah Cowan Guest

    Ioannis Vranos wrote:

    > So what is the need of printf("%ls") in C95 since we got wprintf()?


    printf("%s") prints a multibyte character string to stdout as a sequence
    of bytes.
    printf("%ls") converts a wide character string to a multibyte character
    string, and prints it out as a sequence of bytes.
    wprintf("%s") converts a multibyte character string to a wide character
    string, and prints it out as a sequence of wchar_t to stdout (which must
    be wide-oriented). The wide-oriented stream will in turn convert the
    wide characters into multibyte character sequences before writing.
    wprintf("%ls") prints a wide character string to stdout (which must be
    wide-oriented) as a sequence of wchar_t.

    The only real difference between non-w* I/O functions and the w* ones,
    is that the latter are for "wide oriented" streams while the former are
    for byte-oriented streams. The results end up being the same, AIUI.

    The only thing I can think of that would truly bother me not to have, if
    I was forced to stick to pre-C95 code, is the lack of the wctype.h
    stuff. That seems pretty important, to me, because without them, you can
    convert mbc to wc, but you can't tell much _about_ that wc.

    Ah, well.

    > Wan't there any possibility to print wide-character strings or wchar_ts
    > under C90 directly?


    Yes. Use wcstombs() or somesuch, first. This is what %ls does implicitly
    in printf().

    (Disclaimer: this is all AIUI. I have very rarely used any of this
    stuff, and so there may be major gaping holes in my understanidng. This
    is from carefully reading, skimmed (but hopefully relevant), portions of
    the C Standard.)

    --
    Micah J. Cowan
    Programmer, musician, typesetting enthusiast, gamer...
    http://micah.cowan.name/
     
    Micah Cowan, Feb 29, 2008
    #4
    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. Alex Polite

    java printf

    Alex Polite, Jun 5, 2004, in forum: Java
    Replies:
    18
    Views:
    1,221
    Dale King
    Apr 15, 2006
  2. ben
    Replies:
    4
    Views:
    627
    Martin Ambuhl
    Jun 26, 2004
  3. whatluo

    (void) printf vs printf

    whatluo, May 26, 2005, in forum: C Programming
    Replies:
    29
    Views:
    1,257
  4. azza

    printf affects following printf/s

    azza, Oct 17, 2010, in forum: C Programming
    Replies:
    0
    Views:
    437
  5. guru
    Replies:
    8
    Views:
    286
Loading...

Share This Page