Scroll Down to See All
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrftimestrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1yn



Function Details : sprintf

intsprintf(char * str,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 sprintf 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 : const char *

Pointer to read-only string

2nd Parameter

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

3rd 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.

3rd Parameter

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

Read more about parameters of sprintf in parameters section
The sprintffunction in C language Writes formatted output to a string.
The sprintf function writes formatted output to a string. It formats and stores a series of characters and values in the buffer pointed to by str. The format argument is a string containing literal text and format specifiers that describe how subsequent arguments are converted for output.
The sprintffunction takes 3 parameters:
  • char * `str`: Pointer to the destination buffer where the formatted string will be stored.
  • 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. The resulting string is null-terminated. Returns the number of characters written, excluding the null terminator. The caller must ensure the buffer is large enough to store the output, as no bounds checking is performed.
The sprintf function return value :
  • Returns the number of characters written if successful or a negative value if an error occurred

Output

This example demonstrates basic usage of sprintf to format a string with an integer and a float.