-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.c
46 lines (42 loc) · 867 Bytes
/
input.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
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include "resource_control.h"
#include "input.h"
char *read_name(void){
read_line();
}
char * read_pass(void){
char* str = NULL;
char c;
int leng = 0;
while((c=getch()) != '\r') {
if(c == '\b') {
if(leng != 0) {
str = realloc(str, --leng);
printf("\b \b");
}
}
else {
printf("*");
str = realloc(str, ++leng);
str[leng-1] = c;
}
}
str = realloc(str, ++leng);
str[leng-1] = '\0';
return str;
}
char * read_line(void){
char *ln=NULL,g;
int i=0;
do{
g=getchar();
ln=realloc(ln,i+1);
*(ln+i)=g;
i++;
}
while(g!='\n');
*(ln+i-1)='\0';
return ln;
}