Get_pass.c
上传用户:dq031136
上传日期:2022-08-08
资源大小:802k
文件大小:1k
- #include <stdio.h>
- #include <conio.h>
- #include <string.h>
- #define BACKSPACE 8
- char *get_password(const char *prompt)
- {
- static char buffer[128];
- int i = 0;
-
- char letter = NULL;
- printf(prompt);
- while ((i < 127) && (letter != 'r'))
- {
- letter = getch();
- if (letter == BACKSPACE)
- {
- if (i > 0)
- {
- buffer[--i] = NULL; // Erase previous *
- putchar(BACKSPACE);
- putchar(' ');
- putchar(BACKSPACE);
- }
- else
- putchar(7); // BELL
- }
- else if (letter != 'r')
- {
- buffer[i++] = letter;
- putchar('*');
- }
- }
- buffer[i] = NULL;
- return (buffer);
- }
- void main(void)
- {
- char *password;
- password = get_password("Enter Password: ");
- if (strcmp(password, "Bible"))
- printf("nPassword Incorrectn");
- else
- printf("nPassword OKn");
- }