c 密码

来源:百度知道 编辑:UC知道 时间:2024/05/23 14:13:30
FILE *fp;
fp=fopen("E:\\pw.txt","w");
char ch;
printf("please input:");
for(;(ch=getchar())!='\n';)
{
fputc(ch,fp);
printf("\b*");/* \b 退格 */
}
设想是输入密码字符,输入一个,写入文件,然后在屏幕上删除,显示一个星号,如此循环,直到输入回车。但是不行,该怎么实现上述功能。

/*看看我写的这个合你的要求不?你的题目没给明确我只写了这个简单的,你如果要限制密码只能是4位把password加个判断就好了
if(password>999&&password<10000)

else*/
#include<stdio.h>
#include<windows.h>
void main()
{
int password=0;
int temp=0;
printf("请设置密码:\n");
scanf("%d",&password);
printf("密码设置OK");
Sleep(1000);
system("cls");
printf("请输入密码:\n");
while(1)
{
scanf("%d",&temp);
if(temp==password)
{
printf("密码正确\n");
break;
}
else
{
system("cls");
printf("密码错误,请重新输入:\n");
}
}
}