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
What are the types of data structures in c?
Disadvantages of C language.
Why is struct padding needed?
Why is this loop always executing once?
Write a program to identify if a given binary tree is balanced or not.
What is the use of function in c?
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
Explain how can I right-justify a string?
What are the usage of pointer in c?
How can I prevent another program from modifying part of a file that I am modifying?
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.
What are the types of data files?
i got 75% in all semester am i eligible for your company
What is the best way to comment out a section of code that contains comments?
Why do we write return 0 in c?