sprintf() and printf()

This is a discussion on sprintf() and printf() within the C Programming forums, part of the General Programming Boards category; What's the difference between sprintf() and printf()? And can you explain them both for me please Thanks edit... also, what ...

  1. #1
    Brita like the water
    Join Date
    Mar 2005
    Location
    Look at the palm of your hand, its somewhere in there
    Posts
    9

    sprintf() and printf()

    What's the difference between sprintf() and printf()?

    And can you explain them both for me please Thanks

    edit... also, what is count++. is count something defined in a headerfile, or wha..? ++ just increments count?
    Last edited by Brittany; 03-14-2005 at 11:56 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    printf displays formatted output to the standard output device. It takes any number of parameters* and depending on various sequences in the first argument to it, gives you different formatted ouput.

    sprintf does the exact same thing, except instead of displaying it to an output device, it stores that in a string you pass to it.

    The sequence:
    Code:
    object++
    Increments the value of object. So, depending on what datatype object is, it gets incremented by one.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    68
    Depends where did you see count++? Usually a variable is initiated within a function or passed to a function. count is probably initiated somewhere within the function.

    As for printf and sprintf

    Code:
    int printf(const char *format, ...);
    int sprintf(char *str, const char *format, ...);
    sprintf basically copies a format similar to that you would use in printf except with sprintf it copies it to a string, as with printf it sends it to stdout.

    [edit]
    damn quzah you beat me
    [/edit]

  4. #4
    Brita like the water
    Join Date
    Mar 2005
    Location
    Look at the palm of your hand, its somewhere in there
    Posts
    9
    When you say it sends it to stdout, do you mean it pretty much shows up on the monitor? And what do you mean by copies it to a string? When I said count++ it was inside a set of
    Code:
     { }
    and it wasnt defined anywhere in the progam. It was at the very end. Thanks
    Last edited by Brittany; 03-15-2005 at 12:23 AM.

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well count was declared some place, or your code doesn't compile. stdout is the definition of the standard output device. This is commonly the monitor, though it doesn't have to be. Why don't you go look up the man pages, or search the forums for sprintf. Why, I bet there's even an example of it being used in teh FAQ.

    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Brita like the water
    Join Date
    Mar 2005
    Location
    Look at the palm of your hand, its somewhere in there
    Posts
    9
    will do ^_^ thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. get keyboard and mouse events
    By ratte in forum Linux Programming
    Replies: 10
    Last Post: 11-17-2007, 05:42 PM
  2. repacing printf with sprintf please help
    By nagu in forum C Programming
    Replies: 14
    Last Post: 04-16-2005, 10:58 AM
  3. how to replace printf with sprintf?
    By nagu in forum C Programming
    Replies: 1
    Last Post: 04-12-2005, 08:07 AM
  4. Multithreading problem
    By Bacardi34 in forum C Programming
    Replies: 5
    Last Post: 09-02-2004, 03:26 PM
  5. is there any way to write a float to a ch string
    By mayfda in forum C++ Programming
    Replies: 4
    Last Post: 11-19-2002, 06:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21