FIX: printf Does Not Recognize "\n\r" when Using Conversion

Last reviewed: September 18, 1997
Article ID: Q117385
1.00 1.50 | 1.00
WINDOWS   | WINDOWS NT
kbprg kbfixlist kbbuglist

The information in this article applies to:

  • The C Run-time (CRT), included with:

        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
        - Microsoft Visual C++ 32-bit Edition, version 1.0
    

SYMPTOMS

If an explicit type-conversion syntax is used for the return value of printf(), printf() does not recognize the escape sequence \n\r in its format string.

The following macro prints "<string x>\n\r":

   #define PRINT(x) void( printf("%s\n\r", x ) )

RESOLUTION

To correct the error, use one of the following workarounds:

  1. Use ASCII values for the line feed and carriage return. For example:

          #define PRINT(x)  void( printf("%s%c%c",x,10,13 ) )
    

    -or-

  2. Use explicit typecasting instead. For example:

          #define PRINT(x)  (void)( printf("%s\n\r",x ) )
    

    -or-

  3. Program without the conversion or casting if possible. For example:

          #define PRINT(x)  printf("%s\n\r", x )
    

STATUS

Microsoft has confirmed this to be a bug in the products listed at the beginning of this article. This problem was corrected in Visual C++ 32-bit Edition, version 2.0.


Additional reference words: 1.00 1.50
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: CRTIss
Keywords : CRTIss kbbuglist kbfixlist kbprg
Version : 1.00 1.50 | 1.00
Platform : NT WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.