Comment detail
出力の一時停止と再開 (Nested Flatten)This comment is reply for 6347 匿名: こんにちは。 このコードは環境に依存し...(出力の一時停止と再開). Go to thread root.
ども、raynstardです。 入力がブロッキングされてしまうのは 入力モードを変更してあげないからですね。 UNIXでgetche()の作り方というのを調べるといろいろと出てくると思います。 ポイントはtermiosでカノニカルモードを解除してあげていることと 標準出力のバッファリングをなしにしているところでしょうか? 標準入力の方はおまけです。 // gcc -Wall -std=c99 doukaku179.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | #include <stdio.h>
#include <stdbool.h>
#include <termios.h>
#include <time.h>
static struct termios termios_save;
static bool isContinued = true;
static bool enableOutputScreen = true;
int initKeyInput(void)
{
struct termios t;
tcgetattr(0, &termios_save);
tcgetattr(0, &t);
t.c_lflag &= ~(ICANON|ECHO);
t.c_cc[VMIN] = 0;
t.c_cc[VTIME] = 0;
tcsetattr(0, TCSANOW, &t);
setvbuf(stdin, NULL, _IONBF, 0);
return 0;
}
int main(int argc, char *argv[])
{
char key;
ssize_t read_size;
time_t old, now;
initKeyInput();
setvbuf(stdout, NULL, _IONBF, 0);
old = 0;
while( isContinued )
{
now = time(NULL);
if( now != old )
{
old = now;
if( enableOutputScreen == true )
{
printf("a");
}
}
read_size = fread(&key, 1, sizeof(key), stdin);
if( read_size > 0 )
{
switch( key )
{
case 'q': /* quit */
isContinued = false;
break;
case 'p': /* pause */
enableOutputScreen = (enableOutputScreen != true);
break;
default:
break;
}
}
}
tcsetattr(0, TCSANOW, &termios_save);
printf("\n");
return 0;
}
/* EOF */
|




匿名
#6381()
[
C++
]
Rating0/0=0.00
うーん。こんにちは。 えらそうなこと言っておきながら仕様満たしてなかったですね。 1秒毎に表示するようにしました。 ほかの方などがいわれてるの見て気づいたんですけど、あるぅぇえええ??って感じです。(汗
Rating0/0=0.00-0+