Sprintf .....

Discussion in 'C Programming' started by Savio, Sep 30, 2005.

  1. Savio

    Savio Guest

    Hi guys ,,

    Can anyone out there tell me what is sprintf "

    SAvio
    Savio, Sep 30, 2005
    #1
    1. Advertising

  2. Charles M. Reinke, Sep 30, 2005
    #2
    1. Advertising

  3. Savio

    Eric Sosman Guest

    Savio wrote On 09/30/05 13:29,:
    > Hi guys ,,
    >
    > Can anyone out there tell me what is sprintf "


    Like printf(), except that its "output" goes into a
    character array that you provide instead of being sent
    to stdout. The array must be large enough to hold all
    the characters plus a terminating '\0'.

    --
    Eric Sosman, Sep 30, 2005
    #3
  4. "Savio" <> writes:
    > Hi guys ,,
    >
    > Can anyone out there tell me what is sprintf "
    >
    > SAvio


    Does your C implementation include documentation? On any Unix-like
    system, "man sprintf" should provide all the information you need; I
    don't know about other systems.

    Any decent book on C should explain sprintf. If you don't have a
    decent C book, you should get one. Kernighan & Ritchie's _The C
    Programming Language_, 2nd Edition, is an excellent tutorial.
    Harbison & Steele's _C: A Reference Manual_, 5th Edition, is an
    excellent reference.

    You're posting through groups.google.com. You should be aware that
    Google also provides an excellent web search engine.

    There are all things you should try *before* posting to Usenet.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Sep 30, 2005
    #4
  5. Emmanuel Delahaye, Oct 1, 2005
    #5
  6. Savio

    Mabden Guest

    "Savio" <> wrote in message
    news:...
    > Hi guys ,,
    >
    > Can anyone out there tell me what is sprintf "


    printf() writes a string to the output (the screen or whatever).
    sprintf() writes one string into another string. Remember, you have to
    allocate memory for the string you write to!

    You use it to build a string you want to output later, so if you might
    want to put the first name, then the last name, then the zodiac sign
    into a string, you would use sprintf() to do it.

    --
    Mabden
    Mabden, Oct 4, 2005
    #6
  7. Savio

    Michael Mair Guest

    Mabden wrote:
    > "Savio" <> wrote in message
    > news:...
    >
    >>Hi guys ,,
    >>
    >> Can anyone out there tell me what is sprintf "

    >
    >
    > printf() writes a string to the output (the screen or whatever).
    > sprintf() writes one string into another string. Remember, you have to
    > allocate memory for the string you write to!
    >
    > You use it to build a string you want to output later, so if you might
    > want to put the first name, then the last name, then the zodiac sign
    > into a string, you would use sprintf() to do it.


    Apart from that: If you use a C99 implementation or if your standard
    library contains the function, use snprintf() instead of sprintf()
    as you can easier avoid buffer overflows and similar -- and have
    a chance to find out that the output has been truncated.

    See for example the excellent C99 library reference at dinkumware.com
    for more information.


    Cheers
    Michael
    --
    E-Mail: Mine is an /at/ gmx /dot/ de address.
    Michael Mair, Oct 4, 2005
    #7
    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. shea martin

    sprintf

    shea martin, Sep 2, 2004, in forum: Java
    Replies:
    5
    Views:
    3,584
    shea martin
    Sep 3, 2004
  2. Pep
    Replies:
    5
    Views:
    4,049
  3. CJ
    Replies:
    1
    Views:
    1,312
    Davlet Panech
    Oct 28, 2003
  4. Mike Chirico
    Replies:
    2
    Views:
    3,823
    Grumble
    Nov 19, 2003
  5. Pilatus
    Replies:
    3
    Views:
    537
    Pilatus
    Dec 18, 2003
Loading...

Share This Page