EmbLogic's Blog

difference b/w printf ,fprintf,snprintf and sprintf

printf, fprintf, sprintf, snprintf

Defined in header <stdio.h>
(1)
?int printf( const char          *format, … );?
 
?int printf( const char *restrict format, … );?
 
(2)
int fprintf( FILE          *stream, const char          *format, … );
 
int fprintf( FILE *restrict stream, const char *restrict format, … );
 
(3)
int sprintf( char          *buffer, const char          *format, … );
int sprintf( char *restrict buffer, const char *restrict format, … );
 
int snprintf( char *restrict buffer, int buf_size,
const char *restrict format, … );
(4)  

Loads the data from the given locations, converts them to character string equivalents and writes the results to a variety of sinks.

1) Writes the results to stdout.
2) Writes the results to a file stream stream.
3) Writes the results to a character string buffer.
4) Writes the results to a character string buffer. At most buf_size – 1 characters are written. The resulting character string will be terminated with a null character, unless buf_size is zero.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>