Keyboard input/Flush the keyboard buffer: Difference between revisions
Content added Content deleted
Line 827: | Line 827: | ||
fseek(stdin, 0, SEEK_END); |
fseek(stdin, 0, SEEK_END); |
||
// |
// A very dirty solution - an unbuffered stream does not need any flushing. |
||
// any flushing etc. It should be safe - i.e. if called before any I/O then |
|||
// no trace of buffered characters remain in RAM. Use with care. |
|||
// |
// |
||
// setvbuf(stdin, NULL, _IONBF, 0); |
// setvbuf(stdin, NULL, _IONBF, 0); |
||
// Now we are able to check if the buffer is really empty. |
// Now we are able to check if the buffer is really empty. |
||
// BTW, NEVER use gets due to possible the buffer overrun. |
|||
// |
// |
||
fgets(text, sizeof(text), stdin); |
fgets(text, sizeof(text), stdin); |