User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:conio.h:ungetch
click
to support this page (eg 0,42 € or so) Thanks.

ungetch

int ungetch(int ch);

description of ungetch

Pushes a character back into the keyboard buffer.

return
Successful execution ungetch returns the character ch.
If an error occurs, the function returns EOF.

#include <stdio.h>
#include <ctype.h>
#include <conio.h>
 
int main(void)
{
   int i=0;
   char ch;
   puts("Input an integer followed by a char:");
 
   while((ch = getche()) != EOF && isdigit(ch))
      i = 10 * i + ch - 48; 
 
   if (ch != EOF)
      ungetch(ch);
  printf("\n\ni = %d, next char in buffer = %c\n", i, getch());
   return 0;
}

output of ungetch c example

 The answer is almost 42
 horizontal cursor position from where this text appears = 1
 
 c:\Borland>ungetch.exe
 Input an integer followed by a char:
 1c
 
 i = 1, next char in buffer = c

advertising
c/conio.h/ungetch.txt · Last modified: 2013/02/12 23:23 by 158.181.88.241

Impressum