sprintf function

sprintf composes a string with the same text that would be printed if format was used on printf, but instead of being printed, the content is stored as a C string in the buffer pointed by str.
The size of the buffer should be large enough to contain the entire resulting string.
A terminating null character is automatically appended after the content.
After the format parameter, the function expects at least as many additional arguments as needed for format.


#include <stdio.h>

int main ()
  char buf[50];
  //sprintf(<string, chars to store format>,"<full format>", <value 1>, <value 2>, <...... value n>)
  sprintf (buf, "%d plus %d is %d", 1, 2, 1+2);

  printf ("%s",buf); // printing buf char array
  return 0;


1 plus 2 is 3