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 the advantages of using typedef in a program?

885


Explain object slicing in c++?

803


What is null c++?

844


What is the use of endl in c++?

806


Write a program for Divide a number with 2 and Print the output ( NOTE: Check for divide by zero error).

898


What is the rule of three?

786


What are the syntactic rules to be avoid ambiguity in multiple inheritance?

932


Reads in the size of a square from the screen; 2. Prints a hollow square of that size out of “-“, “|” and blanks on screen; 3. Prints the same hollow square onto a text file. Your program should work for squares of all side sizes between 1 and 20. --- │ │ │ │ │ │ ---

1883


Is turbo c++ free?

836


What is the use of register keyword with the variables?

767


Are vectors faster than arrays?

786


What is a forward referencing and when should it be used?

877


What are the various arithmetic operators in c++?

825


How would you obtain segment and offset addresses from a far address of a memory location?

847


How is data hiding achieved in c++?

804