![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 4
![]() |
Hi,
I am making a simple database program in C right now, and I have one problem. I need to know if there is any function that deletes the content of STDIN??? Thanks for help. |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
if you mean to flush stdin, then use
rewind(stdin);
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
rewind(stdin) is not really defined for stdin when it is a terminal or a pipe.- rewind is the same as
fseek (stream, 0L, SEEK_SET) The usual approach is a platform-specific hunk of code. Some wierd compilers actually define fflush(stdin) as valid - this is not standard though because the standard says that fflush(stdin) has undefined behavior. What platform are you on Windows? Linux? |
|
|
|
|
|
#4 |
|
Programming Guru
![]() |
[php]
#include <stdio.h> #define clear_stdin() while(getc(stdin) != '\n') int main(int argc, char* argv) { char bleh = getc(stdin); printf("%c\n", bleh); clsStdin(); bleh = getc(stdin); printf("%c\n", bleh); return 0; } [/php] Output: i am testing i hello world h
__________________
|
|
|
|
|
|
#5 | |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#6 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 4
![]() |
tempest that's not working.
clsStdin() is an undefined reference. Otherwise, my compiler is Dev-C++ |
|
|
|
|
|
#7 |
|
Expert Programmer
Join Date: Sep 2004
Location: Ontario, Canada
Posts: 556
Rep Power: 5
![]() |
Wouldn't you just use fflush(stdin); ?
__________________
Johnny was a chemist's son but Johnny is no more, for what Johnny thought was H2O was H2SO4 |
|
|
|
|
|
#8 | |
|
Expert Programmer
Join Date: Aug 2005
Location: Rotterdam, the Netherlands
Posts: 942
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#9 |
|
Programming Guru
![]() |
Yea, my bad... i compiled it one way and then changed it for asthetics and forgot to change both parts...
__________________
|
|
|
|
|
|
#10 |
|
Professional Programmer
Join Date: Sep 2005
Location: serbia & montenegro
Posts: 484
Rep Power: 4
![]() |
Both fflush( stdin ) and rewind( stdin ) are working.
What the difference then and which one should I use? |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|