C sprintf()

The sprintf() function is same as the printf() function except that the output is put into the array pointed to by buf instead of being written to the stdout. The array pointed to by buf is null terminated.

sprintf() Syntax

int sprintf(char *buf, const char *format, ...);

The return value is equal to the number of characters actually placed into the array.

The sprintf() provides no bound checking on the array pointed to by buf. It means that the array will be overrun if the output generated by sprintf() is greater than the array can hold.

sprintf() Example

After the following code fragments executes, str holds one 2 3 :

char str[80];
sprintf(str, "%s %d %c", "one", 2, '3');

C Online Test

« Previous Function C Examples »

Follow/Like Us on Facebook

Subscribe Us on YouTube