what is the diff between the printf and sprintf functions??
and what is the syntax for this two functions ??

Answer Posted / santhi perumal

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.

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the types of data structures in c?

600


Disadvantages of C language.

660


Why is struct padding needed?

631


Why is this loop always executing once?

617


Write a program to identify if a given binary tree is balanced or not.

684






What is the use of function in c?

713


int i=3; this declaration tells the C compiler to a) reserve space in memory to hold the integer value b) associate the name i with this memory location c) store the value 3 at this location d) all the above

752


Explain how can I right-justify a string?

625


What are the usage of pointer in c?

703


How can I prevent another program from modifying part of a file that I am modifying?

614


write a C program: To search a file any word which starts with ?a?. If the word following this ?a? starts with a vowel.Then replace this ?a? with ?a? with ?an?. redirect with the output onto an output file.The source file and destination file are specified by the user int the command line.

2455


What are the types of data files?

729


i got 75% in all semester am i eligible for your company

1737


What is the best way to comment out a section of code that contains comments?

783


Why do we write return 0 in c?

553