-
Notifications
You must be signed in to change notification settings - Fork 0
/
MaskedInput.c
72 lines (60 loc) · 1.07 KB
/
MaskedInput.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
void Help()
{
printf("\nSyntax:\n");
printf("\nMaskedInput \"[input text]\"\n");
printf("\nExample:\n");
printf("\nMaskedInput \"Password: \"");
printf("\nWill make a masked input with \'Password: \' prompt and it will print result into STDOUT");
printf("\n\n\nCopyright (c) 2020 anic17 Software\n");
}
void BS()
{
putchar('\b');
putchar(' ');
putchar('\b');
}
int main(int argc, char* argv[])
{
if(argc < 2)
{
Help();
return 0;
}
if(!_stricmp(argv[1], "/?") || !_stricmp(argv[1], "--help"))
{
Help();
return 0;
}
fprintf(stderr, "%s", argv[1]);
char str[8192];
int index = 0;
int ch;
while(ch != 13)
{
int ch = getch();
str[index++] = ch;
if(ch == 8)
{
index--;
if(!index <= 0){
BS();
str[--index] = '\0';
}
} else if(ch == 3)
{
exit(3);
}
if(ch == 13){
break;
} else {
if(ch != 8){
fprintf(stderr, "*");
}
}
}
printf("%s", str);
}