본문 바로가기

IT

canonical

#include<stdio.h>

#include<termios.h>

#define QUESTION"do ya wanna "


int get_response(char *q)

{

printf("%s? (y/n) : ",q);

while(1)

{

switch(getchar())

{

case 'y':

case 'Y': return 0;

case 'n':

case 'N':

case EOF: return 1;

}

}

}


/*

int main()

{

int res;

res = respon(que);

return res;

}

*/

int set_crmode()

{

struct termios ttystate;


tcgetattr(0,&ttystate);

ttystate.c_lflag &= ~ICANON;

ttystate.c_cc[VMIN] = 1;

tcsetattr(0, TCSANOW, &ttystate);

}


int tty_mode(int how)

{

static struct termios original_mode;

if(how ==0)

{

tcgetattr(0,&original_mode);

return 0;

}

return tcsetattr(0, TCSANOW, &original_mode);

}



int main()

{

int response;

tty_mode(0);

set_crmode();

response = get_response(QUESTION);

tty_mode(1);

return response;

}



'IT' 카테고리의 다른 글

20141029 시스템 프로그래밍. curses.  (0) 2014.10.29
시스템 프로그래밍 중간고사  (0) 2014.10.29
system programming chapter 5.  (0) 2014.10.08
more1.c  (2) 2014.10.08
창크기 알려주는 프로그램  (0) 2014.10.08