GET_PASS.C
资源名称:C.rar [点击查看]
上传用户:qq5388545
上传日期:2022-07-04
资源大小:29849k
文件大小:1k
源码类别:
界面编程
开发平台:
C/C++
- #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, "1001"))
- printf("nPassword Incorrectn");
- else
- printf("nPassword OKn");
- }