Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/sprintf.html on line 1
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/sprintf.html on line 1
Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/sprintf.html on line 8
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/sprintf.html on line 8
Print formatted output into a string
#include <stdio.h>
int sprintf( char* buf,
const char* format,
... );
- buf
- A pointer to the buffer where you want to function to store the formatted
string.
- format
- A string that specifies the format of the output.
The formatting string determines what additional arguments you need to
provide.
For more information, see
printf().
libc
Use the -l c option to
qcc
to link against this library.
This library is usually included automatically.
The sprintf() function is similar to
fprintf(),
except that sprintf() places the generated output into the
character array pointed to by buf, instead of writing it to a file.
A null character is placed at the end of the generated character string.
The number of characters written
into the array, not counting the terminating null character.
An error can occur while converting a value for output. When an error
occurs,
errno
indicates the type of error detected.
#include <stdio.h>
#include <stdlib.h>
/* Create temporary file names using a counter */
char namebuf[13];
int TempCount = 0;
char* make_temp_name()
{
sprintf( namebuf, "ZZ%.6o.TMP", TempCount++ );
return( namebuf );
}
int main( void )
{
FILE* tf1,* tf2;
tf1 = fopen( make_temp_name(), "w" );
tf2 = fopen( make_temp_name(), "w" );
fputs( "temp file 1", tf1 );
fputs( "temp file 2", tf2 );
fclose( tf1 );
fclose( tf2 );
return EXIT_SUCCESS;
}
ANSI,
POSIX 1003.1
Safety: | |
Cancellation point |
No |
Interrupt handler |
No |
Signal handler |
Read the Caveats |
Thread |
Yes |
It's safe to call this function in a signal handler if the data isn't
floating point.
errno,
fprintf(),
fwprintf(),
printf(),
snprintf(),
swprintf(),
vfprintf(),
vfwprintf(),
vprintf(),
vsnprintf(),
vsprintf(),
vswprintf(),
vwprintf(),
wprintf()
Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/neutrino/lib_ref/s/sprintf.html on line 175
Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/neutrino/lib_ref/s/sprintf.html on line 175