Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,30 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
// Get a chance to make stdin input buffer dirty.
|
||||
//
|
||||
char text[256];
|
||||
getchar();
|
||||
|
||||
// This DOES NOT WORK properly on all modern systems including Linux & W10.
|
||||
// Obsolete, don't use this. BTW, there is no fpurge in MSVC libs in 2020.
|
||||
//
|
||||
// fflush(stdin);
|
||||
|
||||
// Always works. Readed characters may remain somethere in RAM.
|
||||
//
|
||||
fseek(stdin, 0, SEEK_END);
|
||||
|
||||
// A very dirty solution - an unbuffered stream does not need any flushing.
|
||||
//
|
||||
// setvbuf(stdin, NULL, _IONBF, 0);
|
||||
|
||||
// Now we are able to check if the buffer is really empty.
|
||||
//
|
||||
fgets(text, sizeof(text), stdin);
|
||||
puts(text);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
@ -0,0 +1,68 @@
|
|||
#include <stdio.h>
|
||||
#include <stdio.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
void set_mode(int want_key)
|
||||
{
|
||||
static struct termios old, new;
|
||||
if (!want_key) {
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &old);
|
||||
return;
|
||||
}
|
||||
|
||||
tcgetattr(STDIN_FILENO, &old);
|
||||
new = old;
|
||||
new.c_lflag &= ~(ICANON);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &new);
|
||||
}
|
||||
|
||||
int get_key()
|
||||
{
|
||||
int c = 0;
|
||||
fd_set fs;
|
||||
|
||||
FD_ZERO(&fs);
|
||||
FD_SET(STDIN_FILENO, &fs);
|
||||
select(STDIN_FILENO + 1, &fs, 0, 0, 0);
|
||||
|
||||
if (FD_ISSET(STDIN_FILENO, &fs)) {
|
||||
c = getchar();
|
||||
set_mode(0);
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int c = 0;
|
||||
while (c != 'n') {
|
||||
set_mode(1);
|
||||
|
||||
/* flush pending input so we won't format the hardrive
|
||||
because user accidentally typed 'y' before we even prompted */
|
||||
tcflush(STDIN_FILENO, TCIFLUSH);
|
||||
|
||||
printf("Show this prompt again [Yes/No/Ignore you]? ");
|
||||
fflush(stdout);
|
||||
|
||||
switch(c = tolower(get_key())) {
|
||||
case 'y': putchar('\n');
|
||||
break;
|
||||
|
||||
case 'n': printf("\nDone\n");
|
||||
break;
|
||||
|
||||
case 'i': puts("\nI'll ignore keys for 5 seconds");
|
||||
sleep(5);
|
||||
putchar('\n');
|
||||
break;
|
||||
default:
|
||||
puts("\nAssume that was the cat.");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#include <conio.h>
|
||||
#include <tchar.h>
|
||||
|
||||
// Uses only CRT functions. No need to include 'Windows.h'.
|
||||
|
||||
void Kbflush(void)
|
||||
{
|
||||
while (_kbhit())
|
||||
{
|
||||
// The _gettch function reads a single character without echoing it. When reading
|
||||
// a function key or an arrow key, it must be called twice; the first call returns
|
||||
// 0x00 or 0xE0 and the second call returns the actual key code. Source: MSDN.
|
||||
int ch = _gettch();
|
||||
if (ch == 0x00 || ch == 0xE0)
|
||||
(void)_gettch();
|
||||
}
|
||||
}
|
||||
|
||||
int _tmain(void)
|
||||
{
|
||||
Kbflush();
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue