Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>ungetch() push back the last character read from the console</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 ungetch()               Push Back the Last Character Read from the Console

 #include   <conio.h>                    Required for declarations only

 int        ungetch(c);
 int        c;                           Character to be pushed

    ungetch() pushes back 'c', the last character read from the console.
    'c' will then be the next character read.  ungetch() can only be
    called once between read() statements.

       Returns:     The character 'c', if successful.  A return value of
                    EOF indicates an error.

   Portability:     MS-DOS only.

   -------------------------------- Example ---------------------------------

    The following statements get digits and alphabetic characters from
    the console.

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

           char item[80];
           char qty[5];
           int x, y;
           char ch;

           main()
           {
               while (isdigit(ch = getche()))
                     qty[y++] = ch;
               /* process 'qty' */
               if (isalpha(ch))
                  ungetch(ch);
               while (isalpha(ch = getche()))
                     item[x++] = toupper(ch);
               /* process 'item' */
               printf("\n%s %s\n",qty,item);
           }


See Also: ungetc() cscanf() getch() getche()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson