跪求一个:c语言密码验证程序的源代码

如题所述

第1个回答  2012-04-10
#include<stdio.h>
#include<conio.h>
#include<string.h>
char password[10]="hunter";
typedef struct
{
char data[6];
int top;
}stacktype;
void initstack(stacktype *s)
{
s->top=-1;
}
void push(stacktype *s,char x)
{
if(s->top==6)
printf( "stack is full");
else
{
s->top++;
s->data[s->top]=x;
}
}
int pop(stacktype *s)
{
if(s->top==-1) return(0);
else s->top--;return(1);
}
char stacktop(stacktype *s)
{
char x;
if(s->top==-10) return(0);
else x=s->data[s->top];return(x);
}
void programme(stacktype *s)
{
char a;
char b[5];
int i,j,c;
printf( "请输入一个六位数的密码,你只有三次机会:\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=5;j++)
{
c=j;
a=getch();
if((int)a!=8)
{
printf( "*");
push(s,a);
}
else
{
printf("\b \b");
j=c-2;
pop(s);
}
}
for(j=5;j>=0;j--)
{
pop(s);
b[j]=stacktop(s);
}
b[6]='\0';
printf( "\n");
if(strcmp(password,b)==0)
{
printf( "密码正确\n");
break;
}
else
{
printf("密码错误,请再试一次!\n");
continue;
}
}
if(i==3)
printf("密码错误,即刻退出\n");
}
void main()
{
stacktype s;
initstack(&s);
programme(&s);
}
这是个范例,你自己研究研究

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网