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 an iterator class in c++?

601


You run a shell on unix system. How would you tell which shell are you running?

663


If all is successful, what should main return a) 0 b) 1 c) void

558


What are c++ variables?

541


What is a base class?

603






What are structures and unions?

575


Arrange Doubly linked list in the ascending order of its integral value and replace integer 5 with 7?

3704


What are guid?

691


What doescout<<(0==0) print out a) 0 b) 1 c) Compiler error: Lvalue required

575


Is eclipse good for c++?

542


What is implicit conversion/coercion in c++?

657


What is a storage class?

646


What is heap sort in c++?

605


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

842


What are the 2 main types of data structures?

589