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

printf() returns an extra character

The application waits for a specific character "a" in the serial port using getchar()and then outputs a string using printf("hello")once the character is received. The problem is that the application listening for the "hello" gets allways "ahello".

Khen Truong

  • Don't use getchar() to get the input. I believe Keil's getchar() echoes the char back out (I think). Just test RI and then read if ('a' == SBUF) instead.

  • Chapter 8, "Library Reference" has a table listing the Stream Input & Output Routines. The description of getchar says:
    "Reads and echoes a character using the _getkey and putchar routines."

    The detailed description, later in the same chapter, says,
    "The getchar function reads a single character from the input stream using the _getkey function. The character read is then passed to the putchar function to be echoed."

    If you place your cursor on the 'getchar' in your code, then press F1, it will bring up the same description.

    It's my emphasis in both cases, but I think it's fairly clear - it's doing just what it says on the tin!

  • for information please mail me at
    smansouria@yahoo.com
    with complete description
    to get your answer