Hello to All
what is the different between printf & sprintf and scanf & sscanf
I read the help but i dont understand it
printf("Hello world \n"); aprintf("Hello world \n"); ------------------------------ int k; scanf("%d",k); sscanf("%d",k);
.
Thanks = 10x
Mayer
one more school question, I'm sure. It's that time of year again.
Erik
if you dont know the answer
Do not answer !!
He very much know the answer, since any C programmer with at least a couple of weeks of experience do know the difference.
Hint: Have you looked at the different function prototypes for the functions?
printf = print formatted sprintf = string print formatted (note the extra param)
scanf = scan formatted sscanf = string scan formatted (note the extra param)
One more turn through the manual should make it obvious what the difference is.
printf("Hello world \n"); sprintf("Hello world \n"); // You are missing a parameter, and that is your answer.
i understand what the fuction sprintf it does
but for what it good for ???
what is the usage of the function if i dont use it like printf with the serial port
i can use strcpy strcpyn strcat strncat and get the same result
??!!
Please tell me how you would use strcpy(), ... to process an integer zero-filled to five positions? Or how would you use your suggested functions to know the address value of a pointer?
Do you really think that "formatted" in this case is the same as strcpy()? That sounds more like unformatted printing.
If printf() is configured to emit the text to your first serial port, how would you emit text to a memory region in your flash, or on the SPI bus or on a LCD display?
mayer, please don't be offended by the responses here. the people that reply are generally good guys who know a lot, and sometimes they are a little short of breath, too (so am I, sometimes...) you can use sprintf to format data in a certain way. you can easily "mix" types into a destination buffer, before you do something with it. for example, you can format a floating point number according to a predefined desire and have it end up into your buffer. in addition, you can typecast with it. now go read the specification, think again about what you were told here and you'll be alright.
"i understand what the fuction sprintf it does"
That's not what you said in your original post!
"but for what it good for ???"
It's a standard 'C' function - so you should be able to answer that by looking in any 'C' textbook!
This has nothing specifically to do with the 8051 nor Keil - it is plain, vanilla, standard 'C'.
It is good for doing exactly what the manual says that it does:
"The sprintf function formats a series of strings and numeric values and stores the resulting string in buffer."
So, when you want the resulting string stored in a buffer - rather than sent to stdout - that's when you would use sprintf.
If that's not clear enough for you, the manual goes on to explain:
"This function is similar to the printf routine, but it stores the formatted output in buffer rather than sending it to the output stream."
No, you can't?
Think about it: how will you perform formatting with strcpy strcpyn strcat strncat ??
"i understand what the fuction sprintf it does
Why the question? You understand what sprintf() does. It is good for doing what it does, which you understand. It is not good for doing what it does not do, which you should also understand.
i meant what is usage of the fuction in application
for what implementation is good ??
use it with memory or lcd or serial port other things ??
thanks for the help
What it does is clearly answered in the manual.
The reason for it has been clearly answered in this thread.
have you bother to read the threads above? they clearly answer your question. to make a long story short, just google 'sprintf'. you will be amazed to find that it has nothing to do with LCDs (nor with LSDs...), serial ports and alike.
"i meant what is usage of the fuction in application"
You use it exactly as described in the manual; The manual even includes an example of its usage.
http://www.keil.com/support/man/docs/c51/c51_sprintf.htm
Have you actually bothered to look at the manual yet??
As previously stated, this has nothing specifically to do with Keil, nor the 8051, nor embedded systems - it is perfectly straightforward, standard 'C'. Therefore, if you need further examples, just look in your 'C' textbook, or any other standard 'C' tutorial.
"use it with memory or lcd or serial port other things ??"
Yes, it could possibly find application in all those scenarios; in fact, anywhere that you want to place formatted text into a buffer = just as it says in all the Manuals, textbooks, etc...
Sure you can send it to and LCD, and EEPROM. Modify the buffer then send it to the Serial Port.
It is just another library function. Maybe you need it maybe you do not.