generate output into a fixed-length string


#include <stdio.h>
int _bprintf( char *buf, 
              size_t bufsize,
              const char *format, ... );


The _bprintf() function is equivalent to the sprintf() function, except that the argument bufsize specifies the size of the character array buf into which the generated output is placed. A null character is placed at the end of the generated character string. The format string is described under the description of the printf() function.


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 has occurred, errno contains a value indicating the type of error that has been detected.


#include <stdio.h>

void main( int argc, char *argv[] )
    char file_name[9];
    char file_ext[4];

    _bprintf( file_name, 9, "%s", argv[1] );
    _bprintf( file_ext,  4, "%s", argv[2] );
    printf( "%s.%s\n", file_name, file_ext );



Interrupt handler No
Signal handler Yes, but modifies errno
Thread Yes

See also:

cprintf(), errno, fprintf(), printf(), sprintf(), _vbprintf(), vcprintf(), vfprintf(), vprintf(), vsprintf()