KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q39909: _scanf and _cscanf always Echo to the Screen

Article: Q39909
Product(s): See article
Version(s): 5.10
Operating System(s): MS-DOS
Keyword(s): ENDUSER | | mspl13_c
Last Modified: 30-DEC-1988

The following is on Page 177 of the "Microsoft C 5.1 Optimizing
Compiler Run-Time Library Reference" manual:

   Note:
   While scanf normally echoes the input character, it will not
   do so if the last call was to ungetch.

This process does not appear to work correctly. The following code
sample uses _getch() to get a character from the keyboard, then calls
_ungetch(ch) to disable echoing to the screen before calling _cscanf.
The keyboard input echoes to the screen regardless of the call to
_ungetch. If _cscanf is replaced with _scanf, it still echoes to the
screen.

The following program calls _ungetch, then echoes the filename to
the screen when it is read by _scanf; although, according to the
documentation, it should not echo:

------------------------------------------------------------
#include <conio.h>
#include <stdio.h>
#include <ctype.h>

int result;                   /* return value from _scanf */
char buff2[20];               /* buffer for filename */
int ch;                       /* character returned by _getch*/

main()                        /* begin executable code */

{
ch = getch();                 /* read a keyboard character */

cprintf ("please enter file name");
ungetch(ch);                  /* call to _ungetch */
result = scanf("%19s", buff2);                 /* call _scanf */
printf ("\n Number of correctly matched input"
       "items =  %d\n", result);          /* print # of input items */
       }

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.

Copyright Microsoft Corporation 1986-2002.