當前位置:編程學習大全網 - 編程語言 - 跪求壹個:c語言密碼驗證程序的源代碼

跪求壹個:c語言密碼驗證程序的源代碼

#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);

}

這是個範例,妳自己研究研究

  • 上一篇:鄧州義務教育招生入學工作的通知
  • 下一篇:計算機專業是什麽?
  • copyright 2024編程學習大全網