ARM Technical Support Knowledge Articles

PRINTF EXPANDS '0X0A' INTO '0X0A'+'0X0D'

Applies to: General Topics

Answer


Information in this article applies to:


QUESTION

When I output a ' ' character the printf function expands it into a ' ' + ' ' sequence. Here is an example:

unsigned char ch;

ch = 0x0A;            // '
' character
printf("%c",ch);      // output is actually 0x0D + 0x0A ('
'+'
')

ANSWER

The putchar function expands 0x0A character into 0x0A + 0x0D. To avoid this expansion, modify the putchar library routine  as follows and add the source file to your project.

Modified putchar code:

char putchar (char c)  {
#if 0                  // do not expand '
' into CR+LF
  if (c == '
')  {
    while (!TI);
    TI = 0;
    SBUF = 0x0d;       // output CR
  }
#endif                 // end modification
  while (!TI);
  TI = 0;
  return (SBUF = c);
}

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-09-22 12:48:52

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential