View previous topic :: View next topic |
Author |
Message |
webbone
Joined: 20 Sep 2004 Posts: 14 Location: Sacramento, CA
|
printf() to memory - can this be done? |
Posted: Fri Feb 25, 2005 4:20 pm |
|
|
Hi all! Apologies if this is a simple C question but I've only been doing my embedded stuff in C for a few months (after 17 years of only working in assembly).
Is it possible to use printf() and have the output placed into memory? I know there are 'streams' but I'm not sure how to set one up just as a pointer to a memory location. Any suggestions or pointers to some sample code that already exists here on the forum or in the CCS docs would be helpful.
For informational purposes I'm working on a PIC 18F8720 and am using my own routines for managing the serial ports (and other items) and thus need to be able to print to memory so my code can handle the interface to serial and other hardware. |
|
|
MGP
Joined: 11 Sep 2003 Posts: 57
|
|
Posted: Fri Feb 25, 2005 4:27 pm |
|
|
see sprintf() in the compiler manual. |
|
|
webbone
Joined: 20 Sep 2004 Posts: 14 Location: Sacramento, CA
|
|
Posted: Fri Feb 25, 2005 4:40 pm |
|
|
DOH! Thanks. I had completely forgotten about that. |
|
|
Ttelmah Guest
|
|
Posted: Sat Feb 26, 2005 3:09 am |
|
|
Worth adding, that if you don't want the wasted space of a string (implicit with sprintf), you can access the output of 'printf' a character at a time like:
Code: |
void my_output_routine(int8 val) {
//Do what you want with the output character here
}
//Then if you call
printf(my_output_routine,"text to print/n");
//'my_output_routine' will be called 14 times, with each character in turn.
|
For some 'output' uses, this will get rid of the need to have a string to hold the output.
Best Wishes |
|
|
|