CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

printf() to memory - can this be done?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
webbone



Joined: 20 Sep 2004
Posts: 14
Location: Sacramento, CA

View user's profile Send private message

printf() to memory - can this be done?
PostPosted: Fri Feb 25, 2005 4:20 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 25, 2005 4:27 pm     Reply with quote

see sprintf() in the compiler manual.
webbone



Joined: 20 Sep 2004
Posts: 14
Location: Sacramento, CA

View user's profile Send private message

PostPosted: Fri Feb 25, 2005 4:40 pm     Reply with quote

DOH! Thanks. I had completely forgotten about that.
Ttelmah
Guest







PostPosted: Sat Feb 26, 2005 3:09 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group