|
|
View previous topic :: View next topic |
Author |
Message |
JimmyNewbie Guest
|
Question about fputc |
Posted: Wed Mar 25, 2009 2:45 pm |
|
|
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
|
|
Posted: Wed Mar 25, 2009 2:55 pm |
|
|
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
|
|
Posted: Wed Mar 25, 2009 4:38 pm |
|
|
Ttelmah,
Thank you so much for your explain.
Really appreciate your quick response.
Jim |
|
|
|
|
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
|