This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Regarding usage of printf for serial communication

I am writing some serial data transfer apllication, i was seeing some examples given by keil. in that hello world example i have seen. i that they have used printf function which will print in serial window.... there if i am using printf("%x",variable say 'a');there it is appeding a zero at the end of variable. please clarify y it is happening so?

Parents
  • "printf function which will print in serial window"

    No - printf will print to whatever the current implementation of putchar drives:
    http://www.keil.com/support/man/docs/c51/c51_printf.htm

    printf itself is totally oblivious of where its output actually goes.

    "it is appeding a zero at the end of variable."

    What do you mean by that?

    Remember that %x assumes an int, which is 16 bits in C51 - if you pass it something smaller than 16 bits, you will get undefined behaviour...

    Again, read the section in the Manual.

    Or, are your talking about the NUL terminator that 'C' always uses for strings?

Reply
  • "printf function which will print in serial window"

    No - printf will print to whatever the current implementation of putchar drives:
    http://www.keil.com/support/man/docs/c51/c51_printf.htm

    printf itself is totally oblivious of where its output actually goes.

    "it is appeding a zero at the end of variable."

    What do you mean by that?

    Remember that %x assumes an int, which is 16 bits in C51 - if you pass it something smaller than 16 bits, you will get undefined behaviour...

    Again, read the section in the Manual.

    Or, are your talking about the NUL terminator that 'C' always uses for strings?

Children