怎样输入密码时显示*号啊

u010855801 2013-05-31 05:20:24
int choice;
char code[10]="teacher",c[10]; //删除时候使用
int count;
FILE*fp;
fp=fopen("D:\\学生.txt","rb");
if(fp==NULL)
{
printf("file cannot be opened");
exit(1);
}
count=0;
while(fread(s,sizeof(student),1,fp)==1) //读出文件中共有结构体数
count++;
//printf("%d",count);
fclose(fp);
printf("请输入密码:"); //教师操作密码
scanf("%s",c);
if(strcmp(c,code)==0)



{do
{
menuInput1();

{printf("请选择:\n");
scanf("%d",&choice);}
怎样显示出来的时候是*
...全文
332 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
DaiwjDev 2013-05-31
  • 打赏
  • 举报
回复
赵老师 实现的好,只是 我从用过cprintf啊,这个是VC里面才有的吧
sai_johnny 2013-05-31
  • 打赏
  • 举报
回复
主要是getch()函数的运用。赵老师实现的真好~~~~~
艾莎云 2013-05-31
  • 打赏
  • 举报
回复
引用 3 楼 zhao4zhong1 的回复:
#include <conio.h>
#include <stdio.h>
char pw[40];
int i,ch;
FILE *f;
void main() {
    cprintf("\r\nPassword:");
    i=0;pw[i]=0;
    while (1) {
        ch=getch();
        if (ch==13 || i>=39) break;
        switch (ch) {
        case 27:
            cprintf("\rPassword: %40s"," ");
            cprintf("\rPassword: ");
            i=0;pw[i]=0;
            break;
        case 8:
            if (i>0) {
                i--;
                pw[i]=0;
                cprintf("\b \b");
            }
            break;
        default:
            pw[i]=ch;
            i++;
            pw[i]=0;
            cprintf("*");
            break;
        }
    }
    cprintf("\r\n");
    f=fopen("password.txt","w");
    fprintf(f,"%s\n",pw);
    fclose(f);
}
这跟楼主要的格式不一样啊。cprintf 跟 printf 的区别,请问赵老师。
赵4老师 2013-05-31
  • 打赏
  • 举报
回复
#include <conio.h>
#include <stdio.h>
char pw[40];
int i,ch;
FILE *f;
void main() {
    cprintf("\r\nPassword:");
    i=0;pw[i]=0;
    while (1) {
        ch=getch();
        if (ch==13 || i>=39) break;
        switch (ch) {
        case 27:
            cprintf("\rPassword: %40s"," ");
            cprintf("\rPassword: ");
            i=0;pw[i]=0;
            break;
        case 8:
            if (i>0) {
                i--;
                pw[i]=0;
                cprintf("\b \b");
            }
            break;
        default:
            pw[i]=ch;
            i++;
            pw[i]=0;
            cprintf("*");
            break;
        }
    }
    cprintf("\r\n");
    f=fopen("password.txt","w");
    fprintf(f,"%s\n",pw);
    fclose(f);
}
u010855801 2013-05-31
  • 打赏
  • 举报
回复
木有用啊,输入结束后显示的是密码错误。 而且在定义一个字符型变量才c的话,上面本来就有一个数组c【10】,下面用字符串比较函数的时候不是就不行了吗? 而且还遇到的一个问题是这个不可以用删除键的
nanjun520 2013-05-31
  • 打赏
  • 举报
回复
printf("请输入密码:"); while(1) { char c; c=_getch(); if('\r'==c) break; printf("*"); } 输入密码到输入enter结束密码输入

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧