SNPRINTF - formatted output to a string.

(ANSI Standard)

Usage:

#include <stdio.h>
i = snprintf( s, N, control [, arg1, arg2, ...] );

Where:

char *s;
is the string to which the output should be written.
size_t N;
specifies the maximum number of characters that can be written to "s" (including a '\0' to mark the end of the string). If N is zero, the "s" pointer may be null.
const char *control;
is a "printf" control string.
arg1, arg2, ...
are the values to be output.
int i;
is the number of characters that would have been output if N was sufficiently large to permit the entire string. This count does not include the '\0' used to mark the end of the string. If a write error occurs, a negative number is returned.

Description:

"snprintf" writes to the string "s". "snprintf" converts, formats, and prints its arguments under control of the string "control". For a full description of the formatting used by "snprintf", see the documentation for "printf".

The value N specifies the maximum number of characters to be written into the output string, including the '\0' on the end. This means that if the formatted output string is longer than N-1 characters, characters beyond the N-1'st character are discarded and a '\0' character is placed at the end of the string.

Note that "snprintf" returns the number of characters that would have been printed if there was enough room. This means, for example, that in some cases it might be useful to call "snprintf" twice:

See Also:

expl c lib fopen

expl c lib fclose

expl c lib sprintf

Copyright © 2000, Thinkage Ltd.