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

What is a storage class?

633


What is c++ namespace?

700


Is ca high or low level language?

569


If a round rectangle has straight edges and rounded corners, your roundrect class inherits both from rectangle and from circle, and they in turn both inherit from shape, how many shapes are created when you create a roundrect?

651


why and when we can declar member fuction as a private in the class?

1584






Is it possible to have a recursive inline function in c++?

534


Is C++ case sensitive a) False b) Depends on implementation c) True

601


What do you understand by zombie objects in c++?

591


What is the difference between an external iterator and an internal iterator? Describe an advantage of an external iterator?

627


What is vector processing?

654


Is facebook written in c++?

548


Why namespace is used in c++?

591


How can you specify a class in C++?

776


What is data types c++?

531


Is map ordered c++?

578