GeekInterview.com
  I am new, Sign me up!
 
Home C
 

printf and sprintf

 
Category: C
Comments (-1)


What is the difference between printf and sprintf?


sprintf: 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 returns 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.



Read Next: goto Statement



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact  

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape