If fflush(stdin) is improper, how come it works but the recommended method while((I = getchar()) != '\n' && I != EOF) doesn't? I'm talking specifically about the issues involving keyboard input, where you have to call getchar() or fgets() or whatever more than once to get it to take input. Is there a way to get the so-called proper method to work, or would you advise me to continue using the way that seems to work, even though the experts frown on it? BTW: I try to avoid C++, so using cin isn't an option here.
The C standard leaves fflush() undefined for input streams. On some compilers, it does what you expect: it flushes the input stream. On others, it might not. See http://mail.python.org/pipermail/python-de...ber/037939.html for an example.
I figured that, but why the heck doesn't the recommended method work then? (at least for me... I'm using Mingw)
My best guess is that a stream is never opened for input, so it ends on the EOF check. Of course, my C isn't as good as my PHP (which doesn't deal with compilers, really), but I think it's about the same concept (as I've been reading from streams lately).
While input exists, fill the buffer Code (Text): //Variables byte input_buffer[INPUT_TOTAL]={0}; //Functions void input_refresh() { memset(&input_buffer, 0, INPUT_TOTAL); while(kbhit()) { switch(getch()) { case 72:input_buffer[INPUT_UP]=0xFF; break; case 80:input_buffer[INPUT_DOWN]=0xFF; break; case 75:input_buffer[INPUT_LEFT]=0xFF; break; case 77:input_buffer[INPUT_RIGHT]=0xFF; break; case 'z':case 'Z':input_buffer[INPUT_Z]=0xFF; break; case 'x':case 'X':input_buffer[INPUT_X]=0xFF; break; } } } dword input_check(byte a_key) { return input_buffer[a_key]; }