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 are features of c++?

830


What are the advantages of using pointers in a program?

891


What is enum c++?

872


Is map ordered c++?

826


If dog is a friend of boy, is boy a friend of dog?

775


What do you mean by storage classes?

1141


How can virtual functions in c++ be implemented?

834


Write a program to find the reverse Fibonacci series starting from N.

821


What is flush () in c++?

815


What are multiple inheritances (virtual inheritance)?

809


How do I get good at c++ programming?

842


What is the difference between an array and a list?

777


Is java the same as c++?

741


How to declare a function pointer?

772


What are enumerations?

860