What is the Difference between "printf" and "sprintf"?

Answer Posted / prits

printf : Print formatted data to stdout (function)
sprintf:writes its results to a string instead of stdout

#include <stdio.h>

int main ()
{
char buffer [50];
int n, a=5, b=3;
n=sprintf (buffer, "%d plus %d is %d", a, b, a+b);
printf ("[%s] is a %d char long string\n",buffer,n);
return 0;
}

Is This Answer Correct ?    31 Yes 18 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which ide is best for c++?

656


What is endianness?

716


What is a sequence in c++?

661


What is setbase c++?

727


What are formatting flags in ios class?

702






What is the return value of the insertion operator?

713


If I is an integer variable, which is faster ++i or i++?

689


Which one is better- macro or function?

737


What do you mean by global variables?

672


Explain the operation of overloading of an assignment operator.

791


write a c++ program to create class student having datamember name,Roll_no,age,and branch intilcization all the member using constructor print the all the details on the screen.

2339


What is class definition in c++ ?

726


Which programming language's unsatisfactory performance led to the discovery of c++?

916


Is c++ high level programming language?

760


what are the events occur in intr activated on interrupt vector table

1265