Scroll Down to See All
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1yn



Function Details : snprintf

intsnprintf(char * str,size_t size,const char * format,... args) ;

Return Type : int

Integer type (typically 4 bytes, -2,147,483,648 to 2,147,483,647)
Read about return values of snprintf function .

1st Parameter Type : char *

String pointer (array of characters)

1st Parameter

Pointer to the destination buffer where the formatted string will be stored.

2nd Parameter Type : size_t

Platform-specific unsigned type for array indices and memory sizes.

2nd Parameter

The maximum number of characters (including the null terminator) to write to the buffer.

3rd Parameter Type : const char *

Pointer to read-only string

3rd Parameter

A null-terminated format string specifying how to format the output, containing format specifiers like `%d`, `%s`, or `%f`.

4th Parameter Type : ...

Represents a variable number of arguments in a function. Used in functions like `printf` or `fprintf` to accept additional parameters beyond those explicitly declared.

4th Parameter

A variable number of arguments to format and store in the destination buffer.

Read more about parameters of snprintf in parameters section
The snprintffunction in C language Writes formatted output to a string with a length limit.
The snprintf function is similar to sprintf, but it allows you to specify the maximum number of characters to be written to the buffer. This helps prevent buffer overflows. It writes the output to the character string str.
The snprintffunction takes 4 parameters:
  • char * `str`: Pointer to the destination buffer where the formatted string will be stored.
  • size_t `size`: The maximum number of characters (including the null terminator) to write to the buffer.
  • const char * `format`: A null-terminated format string specifying how to format the output, containing format specifiers like `%d`, `%s`, or `%f`.
  • ... `args`: A variable number of arguments to format and store in the destination buffer.
Writes formatted output to the buffer `str` based on the `format` string and additional arguments. Writes at most `size - 1` characters plus the null terminator to avoid buffer overflow. Returns the number of characters that would have been written if the buffer were large enough, excluding the null terminator. If the return value is greater than or equal to `size`, the output is truncated.
The snprintf function return value :
  • Returns the number of characters that would have been written if n had been sufficiently large, not counting the terminating null character
  • If an encoding error occurs, a negative number is returned

Output

This example demonstrates basic usage of snprintf to format a string with a name and age.