Printf problem..

Hi,

This is my program.

int a = 0x0A;

printf("%c",a);

Why is it that the output from the serial port is 0x0D and 0x0A instead of just 0x0A itself?

Thanks..

Parents
  • %c means to print characters.
    0x0A is not a character. It is a code.
    The range of "printable characters" is something like 61 to 7F for lower case a-z and some other for upper case A-Z, plus the !.;; and other types.
    Do a web search for ASCII table.

    if you want to print hex values, rather than the character values, do a printf("%04X", SomeInt);

    HTH,

Reply
  • %c means to print characters.
    0x0A is not a character. It is a code.
    The range of "printable characters" is something like 61 to 7F for lower case a-z and some other for upper case A-Z, plus the !.;; and other types.
    Do a web search for ASCII table.

    if you want to print hex values, rather than the character values, do a printf("%04X", SomeInt);

    HTH,

Children
More questions in this forum