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



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

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

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

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

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

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

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

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

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

Answer / 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

More C Interview Questions

Write a code to determine the total number of stops an elevator would take to serve N number of people.

0 Answers   Expedia,


#&#8206;include&#8236;<stdio.h> void main() { int i; for(i=5;0;i++) { printf("%d",i); } }

2 Answers   Facebook,


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.

0 Answers   Subex,


‘ C’ PROGRAME TO SHOW THE TYPE OF TRANGLE BY ACCEPTING IT’S LENGTH .

0 Answers  


1)what is the error in the following stmt where str is a char array and the stmt is supposed to traverse through the whole character string str? for(i=0;str[i];i++) a)There is no error. b)There shud be no ; after the stmt. c)The cond shud be str[i]!='\0' d)The cond shud be str[i]!=NULL e)i shud be initialized to 1

4 Answers  






Is c an object oriented programming language?

1 Answers  


Differentiate between declaring a variable and defining a variable?

0 Answers  


write a c program to find the roots of a quadratic equation ax2 + bx + c = 0

11 Answers   CSC, St Marys, TATA,


how many times of error occur in C

11 Answers  


What is the use of in c?

0 Answers  


Explain is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

0 Answers  


What does nil mean in c?

0 Answers  


Categories