![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: May 2005
Posts: 1
Rep Power: 0
![]() |
Resetting stdin after EOF
I have a piece of code that looks like this:
---example.c--- #include <stdio.h>
int main() {
char c;
while ((c = getchar()) && (c != EOF))
;
putchar('\n');
c = getchar();
printf("%c\n", c);
}However, if I then redirect input to this program (e.g. dmesg | ./example), then I get a garbage character printed to the console, and the program does not wait for input from the keyboard. I assume this is something to do with resetting stdin - how can I pass input back to the keyboard when stdin has been set to receive input from a redirect? Thanks, Rob |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|