<< Previous | Next >>

snprintf

int snprintf( char * buffer, int len, char * format, ... );

Description

This function takes a string (pointed to by format), arguments of the format, and outputs the formatted string to the buffer pointed to by buffer. snprintf() will only output up to len characters. The user should make sure that:

  • there are enough arguments after format to fill in the format parameters in the format string

  • the types of arguments after format match the format fields in format

For example,

   

snprintf(buffer, BUF_LEN, "%s=%x","variable x",256); 

puts the string "variable x=100" into buffer.

A complete list of valid conversion specifiers (%d, %s, etc.) can be found in the description for printf() under Dynamic C Conversion Specifiers.

The macro STDIO_DISABLE_FLOATS can be defined if it is not necessary to format floating point numbers. If this macro is defined, %e, %f and %g will not be recognized. This can save thousands of bytes of code space.

This function can be called by processes of different priorities.

Parameters

buffer
Location of formatted string.

len
The maximum length of the formatted string.

format
String to be formatted.

...
Format arguments.

Return value

The number of characters written. If the output is truncated due to the len parameter, then this function returns the number of characters that would have been written had there been enough space.

Library

STDIO.LIB

See also

printf, sprintf


Dynamic C Functions << Previous | Next >> rabbit.com