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

Can a list of string be stored within a two dimensional array?

747


What is a responder chain?

779


I want explanation for this assignment: how to connect mysql database using c/c++,please explain this detailly?

1763


What's the order in which the local objects are destructed?

998


Explain one-definition rule (odr).

845






Difference between strdup and strcpy?

854


What is data types c++?

744


What are associate containers?

796


What is lambda in c++?

870


Explain function overloading and operator overloading.

800


How does com provide language transparency?

770


What is the basic of c++?

785


Why are pointers used?

740


What is scope in c++ with example?

820


What is c++ & why it is used?

782