sprintf, swprintf
Go Up to stdio.h Index
Header File
stdio.h
Category
Memory and String Manipulation Routines
Prototype
int sprintf(char *buffer, const char *format[, argument, ...]);
int swprintf(wchar_t *buffer, size_t bufsz, const wchar_t *format[, argument, ...]);
Description
Writes formatted output to a string.
sprintf accepts a series of arguments, applies to each a format specifier contained in the format string pointed to by format, and 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.
Return Value
On success, sprintf returns the number of bytes output. The return value does not include the terminating null byte in the count.
On error, sprintf returns EOF.
Example
#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; }
Portability
POSIX | Win32 | ANSI C | ANSI C++ | |
---|---|---|---|---|
sprintf |
+ |
+ |
+ |
+ |
swprintf |
+ |
+ |
+ |