This shows you the differences between two versions of the page.
c:conio.h:ungetch [2013/02/03 21:04] 127.0.0.1 external edit |
c:conio.h:ungetch [2024/02/16 01:05] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== ungetch ====== | ====== ungetch ====== | ||
<code c> | <code c> | ||
+ | int ungetch(int ch); | ||
</code> | </code> | ||
==== description of ungetch ==== | ==== description of ungetch ==== | ||
- | ungetch is in work by code-reference.com \\ | + | Pushes a character back into the keyboard buffer.\\ |
- | if you are faster... don't hasitate and add it | + | \\ |
+ | return\\ | ||
+ | Successful execution ungetch returns the character ch.\\ | ||
+ | If an error occurs, the function returns EOF.\\ | ||
<code c> | <code c> | ||
- | no example at the moment | + | #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; | ||
+ | } | ||
</code> | </code> | ||
===== output of ungetch c example ===== | ===== output of ungetch c example ===== | ||
- | no example at the moment | + | 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 | ||
+ | |||
+ | {{:c:conio.h:ungetch.png?nolink|}} | ||