| View previous topic :: View next topic |
| Author |
Message |
Unbr0ken Advanced Cheater
Reputation: 2
Joined: 10 Aug 2011 Posts: 67
|
Posted: Sat Aug 18, 2012 1:36 am Post subject: C, flushing the buffer |
|
|
Is there a POSIX/ANSI way to flush the stdin?
| Code: | fflush(stdin); //should not be used.
setbuf(stdin, NULL); //Doesn't work on linux.
while((C = getchar()) != '\n' && C != EOF) //This is just an implementation, I need a standard function.
fseek(stdin, 0, SEEK_END); //Same as setbuf |
So, Is there another way?
Thanks for reading.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sat Aug 18, 2012 11:21 pm Post subject: |
|
|
| tried fpurge?
|
|
| Back to top |
|
 |
Unbr0ken Advanced Cheater
Reputation: 2
Joined: 10 Aug 2011 Posts: 67
|
Posted: Sat Aug 18, 2012 11:34 pm Post subject: |
|
|
fpurge is non-standard (it's not even POSIX) and extremely non-portable; even on systems that support it, it's not recommended.
But thanks for trying to help.
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Aug 19, 2012 9:56 am Post subject: |
|
|
| i know that. just pointing out the common alternative. there is no portable way to do what you want (other than the code you have already posted). tcflush might be closer to what you are looking for
|
|
| Back to top |
|
 |
Unbr0ken Advanced Cheater
Reputation: 2
Joined: 10 Aug 2011 Posts: 67
|
Posted: Sun Aug 19, 2012 2:11 pm Post subject: |
|
|
Well, I finally had to use the implementation. It's the closest way to a standard.
Thanks for help.
|
|
| Back to top |
|
 |
|