What is the purpose of sprintf() function in C Language?

The sprintf() stands for “string print.” The sprintf() function does not print the output on the console screen. It transfers the data to the buffer. It returns the total number of characters present in the string.

Syntax

  1. int sprintf ( char * str, const char * format, … );

Let’s see a simple example

  1.  #include<stdio.h>
  2. int main()
  3. {
  4.  char a[20];
  5.  int n=sprintf(a,“javaToint”);
  6.  printf(“value of n is %d”,n);
  7.  return 0;}

Output:

value of n is 9