snwprintf - standard

Discussion in 'C Programming' started by Googler, Aug 22, 2003.

  1. Googler

    Googler Guest

    > Also is snprintf (the non-unicode version) standard ?
    > in either C90 or C9x ?


    If snprintf is standard, what are similiar results for snprintf ?

    i.e.

    char s[100];

    snprintf(s,5,"Hello");

    What should snprintf return ?
    What should be in the buffer 's' ?

    snprintf(s,4,"Hello");

    Likewise for the above.
     
    Googler, Aug 22, 2003
    #1
    1. Advertising

  2. Googler <> wrote:
    >> Also is snprintf (the non-unicode version) standard ?
    >> in either C90 or C9x ?


    > If snprintf is standard, what are similiar results for snprintf ?
    >
    > char s[100];
    >
    > snprintf(s,5,"Hello");


    7.19.6.5 The snprintf function
    |
    | Synopsis
    |
    | #include <stdio.h>
    | int snprintf(char * restrict s, size_t n,
    | const char * restrict format, ...);
    |
    | Description
    |
    | The snprintf function is equivalent to fprintf, except that the output
    | is written into an array (specified by arguments) rather than to a
    | stream. If n is zero, nothing is written, and s may be a null
    | pointer. Otherwise, output characters beyond the n-1st are discarded
    | rather than being written to the array, and a null character is written
    | at the end of the characters actually written into the array. If copying
    | takes place between objects that overlap, the behavior is undefined.
    |
    | Returns
    |
    | The snprintf function returns the number of characters that would have
    | been written had n been sufficiently large, not counting the terminating
    | null character, or a negative value if an encoding error occurred. Thus,
    | the null-terminated output has been completely written if and only if
    | the returned value is nonnegative and less than n.



    > What should snprintf return ?


    The snprintf function returns the number of characters that would
    have been written had n been sifficiently large.

    > What should be in the buffer 's' ?


    If n is zero, nothing is written, and s may be a null pointer.
    Otherwise, output characters beyond the n-1st are discarded rather
    than being written to the array, and a null character is written at
    the end of the characters actually written into the array.

    > snprintf(s,4,"Hello");
    >
    > Likewise for the above.


    re-read above
     
    William Ahern, Aug 22, 2003
    #2
    1. Advertising

  3. On Fri, 22 Aug 2003 09:50:57 -0400, Googler wrote:

    >> Also is snprintf (the non-unicode version) standard ? in either C90 or
    >> C9x ?


    Since this is a confusing point, it should be noted that the wide
    character functions do not necessarily use Unicode as the wchar_t
    charset. Also many of the regular char functions can handle Unicode if
    the internal encoding is UTF-8.

    Having said that, most mainstream libraries *do* use Unicode values for
    wchar_t and it is pretty hard to write a program without manking any
    assumptions about the internal encoding at all.

    Mike
     
    Michael B Allen, Aug 22, 2003
    #3
    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. Googler

    snwprintf - standard

    Googler, Aug 22, 2003, in forum: C Programming
    Replies:
    1
    Views:
    3,411
    Sven Semmler
    Aug 22, 2003
  2. Googler

    snwprintf - standard

    Googler, Aug 22, 2003, in forum: C Programming
    Replies:
    1
    Views:
    464
    Michael B Allen
    Aug 23, 2003
  3. Googler

    Re: snwprintf - standard

    Googler, Aug 22, 2003, in forum: C Programming
    Replies:
    1
    Views:
    411
  4. steve.leach

    How standard is the standard library?

    steve.leach, Apr 18, 2005, in forum: Python
    Replies:
    1
    Views:
    421
    Christos TZOTZIOY Georgiou
    Apr 18, 2005
  5. funkyj
    Replies:
    5
    Views:
    1,190
    funkyj
    Jan 20, 2006
Loading...

Share This Page