c - 使用 C 实现密码字段

标签 c

是否可以用C语言实现我们在网页上看到的密码字段???

最佳答案

此代码可以达到以下目的:-

#include <stdio.h>
#include <conio.h>

#define MAX 25
#define passfield 1

void main()
{
 char password[MAX], passchar;
 int i=0;
 clrscr();
 printf("Enter password: ");
 while(passfield)
 {
  passchar=getch();
  if(passchar==13)
   break; // 13 is the ASCII value of ENTER
  if(passchar==8) // 8 is the ASCII value of BACKSPACE
  {
   putch('\b');
   putch(NULL);
   putch('\b');
   --i;
   continue;
  }
  password[i++]=passchar; //else store characters in password
  passchar='*'; //mask password character
  putch(passchar);
 }
 password[i]='\0'; //end of the char array
 printf("\n%s",password);
 getch();
}

关于c - 使用 C 实现密码字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8550447/

相关文章:

c - 在 3 次握手期间将 TCP 选项添加到 ACK 数据包

c - 我是否转换 malloc 的结果?

c - 在c中使用POSIX Semaphore进行多线程

c - GDB-remote + qemu 报告静态 C 变量的意外内存地址

python - 如何返回指向ctypes中结构的指针?

c - 在 open62541 中将内存变量从服务器发送到客户端

c - 到矩阵中的点的路径。想通过DP解决

c - 向左移动缓冲区,在 LED 面板上滚动字符串?

c - C 中的浮点与整数数据类型计算问题

c - C代码优化-防止多文件打开