What is the difference between printf and sprintf?

sprintf: This Writes formatted data to a character string in memory instead of stdout


Syntax of sprintf is:


#include <stdio.h>

int sprintf (char *string, const char *format

[,item [,item]...]);


Here


String refers to the pointer to a buffer in memory where the data is to be written. Format refers to pointer to a character string defining the format. Each item is a variable or expression specifying the data to write.


The value returned by sprintf is greater than or equal to zero if the operation is successful or in other words the number of characters written, not counting the terminating null character is returned. And return a value less than zero if an error occurred.


printf: Prints to stdout


Syntax for printf is:


printf format [argument]...


The only difference between sprintf() and printf() is that sprintf() writes data into a character array, while printf() writes data to stdout, the standard output device.

Questions by GeekAdmin   answers by GeekAdmin

Showing Answers 1 - 3 of 3 Answers

Have_Phun

  • Feb 3rd, 2007
 

the printf() funkshun is supposed to print the output to stdout here the screen.in sprintf() function we store the formatted o/p on a string buffer.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions