-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgetch.c
More file actions
executable file
·44 lines (36 loc) · 768 Bytes
/
getch.c
File metadata and controls
executable file
·44 lines (36 loc) · 768 Bytes
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
#include <stdio.h>
#include <curses.h>
#include <term.h>
#define MAXCHAR 8
#define CONTROL(x) ((x) & 0x1F)
int main(void)
{
// FILE *fp = fopen("x", "w");
// if (fp == 0)
// return(-1);
SCREEN *s = newterm(NULL, stdin, stdout);
if (s == 0)
return(-1);
cbreak();
noecho();
keypad(stdscr, TRUE);
int i;
char input;
char string[MAXCHAR + 1];
addstr( "What is your name> " );
refresh();
for(i = 0; i <= MAXCHAR; i++){
input = getch();
refresh();
// printf("%c\n", input);
if(i == MAXCHAR){
break;
}
else{
string[i] = input;
}
}
printf("%s\n", string);
endwin();
return 0;
}