Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old May 22nd, 2005, 8:48 AM   #1
o0zi
Newbie
 
Join Date: May 2005
Posts: 1
Rep Power: 0 o0zi is on a distinguished road
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);
}
Entering input from the keyboard, this program works fine.
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
o0zi is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:50 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC