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

Explain unexpected() function?

582


Explain function overloading and operator overloading.

617


What is virtual base class?

567


Explain dangling pointer.

674


What are the various storage classes in C++?

644






Describe delete operator?

619


What are single and multiple inheritances in c++?

572


Can a class be static in c++?

563


Can you be able to identify between straight- through and cross- over cable wiring? And in what case do you use straight- through and cross-over?

618


What are pointer-to-members? Explain.

624


What is the best it certification?

580


Is c++ used anymore?

585


Specify some guidelines that should be followed while overloading operators?

616


What is switch case in c++ syntax?

622


Why c++ is the best language?

592