what is the diff between the printf and sprintf functions??
and what is the syntax for this two functions ??
Answers were Sorted based on User's Feedback
Answer / guest
printf statement print the result with comment
sprintf statement print the string
Syntax
printf(" ");
sprintf(object name[argument]);
Is This Answer Correct ? | 7 Yes | 1 No |
Answer / vignesh1988i
the printf and sprintf functions are used to output to the
screen.....
in printf... just we can print the necessary things as
we wanted
SYNTX is:: printf("format specifiers..(%d or %c
etc)",list of agruments..(arg1,arg2... arg n);
hrewr this function directly output whatever you are giving
inside ....
but sprintf is called Stream printf... where it will store
whatever we output to the screen in an array (ie..stream)
and then output to the screen;;;
sprintf(array base address,"format specifications",variables);
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / jack
The printf subroutine converts, formats, and writes the
Value parameter values, under control of the Format
parameter, to the standard output stream.
The sprintf subroutine converts, formats, and stores the
Value parameter values, under control of the Format
parameter, into consecutive bytes, starting at the address
specified by the String parameter. The sprintf subroutine
places a null character (\0) at the end. You must ensure
that enough storage space is available to contain the
formatted string.
Is This Answer Correct ? | 2 Yes | 1 No |
Answer / manoj
i agree with Vignesh, and one more thing i would like to
add is,
ex:
char b[100];
sprintf( b, "Formatted data: %d / %f", i, f );
In above program, in array b string "Formatted data: %d / %
f" with proper i and f value will be stored.
it will not be printed on the output screen.
Is This Answer Correct ? | 1 Yes | 1 No |
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 |
explain what are actual arguments?
I was asked to write a program in c which when executed displays how many no.of clients are connected to the server.
Should a function contain a return statement if it does not return a value?
What is the mean of this statement:: if(int i=0 * i=9)
If errno contains a nonzero number, is there an error?
Write a C Program to display the following menu: Menu 1. Display 2. Copy 3. Append 4. Exit Accept the choice (1-4) from the user, and perform the following tasks: Choice 1: Accept a file name from the user and display the file on screen Choice 2: Accept two file names, and copy first file to the second Choice 3: Accept two file names, and append second file to the first file Choice 4: Terminate the program
1 Answers Accenture, Concor, DMU, Satyam, Syntel, Tora,
what would be the output of the following program main() { int a[] = {1,2,3,4,5}; int *ptr = {a,a+1,a+2,a+3,a+4}; printf("%d %d %d %d",a,*ptr,**ptr,ptr); } }
What is getche() function?
What is #include in c?
How. To pass the entrance test
How are pointers declared in c?
How can I read/write structures from/to data files?