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

Question about fputc

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







Question about fputc
PostPosted: Wed Mar 25, 2009 2:45 pm     Reply with quote

hi,
From the compiler user guide, fputc is used to output one character at a time. But when I am doing the following, the compiler won't give any error and the output seems correct to output the string in debug port.
Code:
void send_data_to_debug_port(char cIn)
{
  fputc(cIn,DEBUG_PORT);
}


--> calling send_data_to_debug_port("this is a test\r\n");

Can anyone explain why this correct?
Ps: I am using verison 4.087. As far as I remember, this also works with the previous version.

Thanks,
Jim
Ttelmah
Guest







PostPosted: Wed Mar 25, 2009 2:55 pm     Reply with quote

This is a standard CCS extension.
It is in the manual, in the stuff about constant strings.
Basically (for example), if you have:

putc("Test string\n");

The function putc (which only accepts single characters), will be automatically called repeately, with all the characters in the constnt string, one after another.

The same works with any function that accepts a single integer.

So:
Code:

void demo(int8 val) {
    printf("character value %d\n");
}

//called as:

demo("ABCD");


Will outputs four lines, with the ascii values of each character in turn.

Best Wishes
JimmyNewbie
Guest







PostPosted: Wed Mar 25, 2009 4:38 pm     Reply with quote

Ttelmah,
Thank you so much for your explain.
Really appreciate your quick response.
Jim
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