10.curses

1.curses 개요

2. 기본 출력

ex)base.c

#include <unistd.h>

#include <stdlib.h>

#include <curses.h>

int main()

{

initscr();

move(5,15);

printw("%s","Hello!");

refresh();

sleep(2);

endwin();

}

3.출력 예제

#include <unistd.h>

#include <stdlib.h>

#include <curses.h>

int main()

{

const char witch_one[]="-v-";

const char *scan_ptr;

initscr();

move(5,15);

attron(A_BOLD);

printw("%s","서시");

attroff(A_BOLD);

refresh();

sleep(1);

move(8,15);

attron(A_DIM);

printw("%s","윤동주");

attroff(A_DIM);

refresh();

sleep(1);

move(10,10);

printw("%s","죽는날 까지 하늘을 우러러");

move(11,23);

printw("%s","한점 부끄럼이 없기를");

move(13,10);

printw("%s","입새에 이는 바람에도 나는 괴로와 했다.");

move(14,23);

printw("%s","별을 노래하는 마음으로 ");

refresh();

sleep(1);

attron(A_DIM);

scan_ptr = witch_one + strlen(witch_one);

while(scan_ptr != witch_one)

{

move(10,10);

insch(*scan_ptr);

}

attroff(A_DIM);

endwin();

}

4.입력 예제

#include <unistd.h>

#include <stdlib.h>

#include <curses.h>

#include <string.h>

#define PW_LEN 25

#define NAME_LEN 256

int main()

{

char name[NAME_LEN];

char password[PW_LEN];

char *real_password="aksemrdl";

int i=0;

initscr();

move(5,10);

printw("%s","Please login:");

move(7,10);

printw("%s","User name:");

getstr(name);

move(9,10);

printw("%s","Password:");

refresh();

cbreak();

noecho();

memset(password,0,sizeof(password));

i=0;

while(i<PW_LEN)

{

password[i]=getch();

move(9,20+i);

addch('*');

refresh();

if(password[i]=='\n')break;

if(strcmp(password,real_password)==0)break;

i++;

}

echo();

nocbreak();

move(11,10);

if(strcmp(password,real_password)==0)printw("%s","Correct");

else printw("%s","Wrong");

refresh();

endwin();

exit(1);

}