|
||||||||
|
Technical Support Support Resources
Product Information |
GENERAL: PRINTF EXPANDS '0X0A' INTO '0X0A'+'0X0D'Information in this article applies to:
QUESTIONWhen I output a '\n' character the printf function expands it into a '\r' + '\n' sequence. Here is an example:
unsigned char ch;
ch = 0x0A; // '\n' character
printf("%c",ch); // output is actually 0x0D + 0x0A ('\r'+'\n')
ANSWERThe 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 '\n' into CR+LF
if (c == '\n') {
while (!TI);
TI = 0;
SBUF = 0x0d; // output CR
}
#endif // end modification
while (!TI);
TI = 0;
return (SBUF = c);
}
MORE INFORMATION
SEE ALSO
Last Reviewed: Thursday, September 22, 2005 | |||||||
|
||||||||