Knowledge Base
Home C

printf and sprintf

Category: C | Comments (0)

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.


Next: goto Statement




Post Comment


Members Please Login

Name:


Email:
 
(Optional. Used for Notification)

Title:

 
Comment:


Validation Code:
 <=>  (Enter this code in text box)
Subscribe





Daily Email Updates

Get Latest Knowledge Base Updates delivered directly to your Inbox...

Enter your email address:

Latest Knowledge Base Updates
 

C Tutorials

 

Related Tutorials