Is there any c library function to convert an integer to a string...What is the use of stoi()
excellent
Good
informative
foolish
Is there any c library function to convert an integer to a string...What is the use of stoi()
sprintf.
Learn to read manual.
Surely, you can read the documentation to find out how sprintf() works. Of, failing that, google it.
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; }