Go to the first, previous, next, last section, table of contents.


snprintf

Syntax

#include <stdio.h>

int snprintf (char *buffer, size_t n, const char *format,
              ...);

Description

This function works similarly to sprintf() (see section sprintf), but the size n of the buffer is also taken into account. This function will write n - 1 characters. The nth character is used for the terminating nul. If n is zero, buffer is not touched.

Return Value

The number of characters that would have been written (excluding the trailing nul) is returned; otherwise -1 is returned to flag encoding or buffer space errors.

The maximum accepted value of n is INT_MAX. INT_MAX is defined in <limits.h>. -1 is returned and errno is set to EFBIG, if n is greater than this limit.

Portability

ANSI (see note 1)

Notes:

  1. The buffer size limit is imposed by DJGPP. Other systems may not have this limitation.


Go to the first, previous, next, last section, table of contents.