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 |
DIFFERNCE BETWEEN THE C++ AND C LANGUAGE?
what does keyword ‘extern’ mean in a function declaration?
how to find a 5th bit is set in c program
How to write a program for machine which is connected with server for that server automatically wants to catch the time for user of that machine?
How is a null pointer different from a dangling pointer?
Blade logic interview question. 1st round is a written tests with 15 multiple questions from c and c++. All are simple basic question. Like int main () { Int i=65; Return printf(“%c”, i); } 2nd and 3rd round is technical interview. The position for which I was interview was core UNIX and c. Yes it is for system programming. The company has product name blade server. For their server they are creating their own command for their purpose. Example cd command. We can implement it in a c program by using the chdir() function. So the question asks related to PID, fork, pipe, shared memory, signal. Write a program in c which will act as cp command.
1 Answers BladeLogic, Infosys,
Find Index of least significant bit set in an Integer. ex. int value is say 10001000 results should be 4.
what is the differnce between programing langauge and tool? is sas is a programing langauge r tool?
1.int a=10; 2.int b=20; 3. //write here 4.b=30; Write code at line 3 so that when the value of b is changed variable a should automatically change with same value as b. 5.
main() { int a; a=++100; printf("%d",a); getch(); }
What are identifiers c?
How can I find the modification date and time of a file?