資源簡介
利用select函數,實現了從terminal端輸入數據,然后輸出到指定的文件中,適合新手,如果有什么問題,歡迎在下面評論。
代碼片段和文件信息
/*************************************************************************
>?File?Name:?keyboard.c
>?Author:?Crazycuo
>?Mail:?740094202@qq.com?
>?Created?Time:?2014年09月20日?星期六?09時34分34秒
?************************************************************************/
#include?
#include?
#include?
#include?
#include?
#include?
#include?
#define?MAXSIZE?100
int?main(void)
{
int?keyboard;
int?file;
int?maxfd;
int?reti;
char?buff[MAXSIZE];
fd_set?readfd;
fd_set?writefd;
struct?timeval?timeout;
keyboard=open(“/dev/tty“O_RDONLY|O_NONBLOCK);
file=open(“/home/crazy/test.txt“O_WRONLY|O_NONBLOCK);
maxfd=keyboard>file?keyboard:file;
maxfd++;
assert(file>0);
assert(keyboard>0);
assert(file>0);
while(1)
{
timeout.tv_sec=3;
timeout.tv_usec=0;
FD_ZE
評論
共有 條評論