View Poll Results: What is the rating you give for this question

Voters
2. You may not vote on this poll
  • excellent

    0 0%
  • Good

    0 0%
  • informative

    0 0%
  • foolish

    2 100.00%

Thread: Converting an integer to a string

  1. #1
    Registered User linuxlover's Avatar
    Join Date
    Nov 2010
    Location
    INDIA
    Posts
    52

    Converting an integer to a string

    Is there any c library function to convert an integer to a string...What is the use of stoi()

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    sprintf.

  3. #3
    Registered User linuxlover's Avatar
    Join Date
    Nov 2010
    Location
    INDIA
    Posts
    52
    Quote Originally Posted by Bayint Naung View Post
    sprintf.
    What is its format and what is its return type

  4. #4
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Learn to read manual.

  5. #5
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Surely, you can read the documentation to find out how sprintf() works. Of, failing that, google it.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    sprintf Sends formatted output to a string.

    Syntax:
    int sprintf(char *buffer, const char *format [, argument, ...]);

    Prototype in:
    stdio.h

    Remarks:
    sprintf does the following:

    * accepts a series of arguments

    * applies to each a format specifier contained in the format string pointed to by format

    * outputs the formatted data to a string

    sprintf applies the first format specifier to the first argument, the second
    to the second, and so on. There must be the same number of format specifiers
    as arguments.

    See printf for details on format specifiers.

    Return Value:
    sprintf returns the number of bytes output. sprintf does not include the
    terminating null byte in the count.

    In the event of error, sprintf returns EOF.

    Portability:
    sprintf is available on UNIX systems and is defined in ANSI C.

    It is compatible with Kernighan and Ritchie.

    Example:
    Code:
     #include <stdio.h>
     #include <math.h>
    
     int main(void)
     {
        char buffer[80];
    
        sprintf(buffer, "An approximation of Pi is %f\n", M_PI);
        puts(buffer);
        return 0;
     }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unable to compare string with 'getter' returned string.
    By Swerve in forum C++ Programming
    Replies: 2
    Last Post: 10-30-2009, 05:56 PM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  4. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  5. Converting a string to an integer
    By Unregistered in forum C++ Programming
    Replies: 3
    Last Post: 08-31-2001, 10:01 PM

Tags for this Thread