修改2楼程序
#ifndef _GETPASSWD_H
#define _GETPASSWD_H
#include <stdio.h>
#include <conio.h>
char passwd[32] = "";
char *getPasswd()
{
char c;
int i = 0;
while ((c=getch()) != '\r')
{
passwd[i++] = c;
putchar('*');
}
passwd[i] = '\0';
return passwd;
}
#endif
//*******************************上面是password.h*******************************************
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
//#include"password.h"
#define PASS "123"
int main()
{
int i,j=0,password=1;
char name1[10],name2[6]="zhang";
char *pw;
printf("please input your name:\n");
gets(name1);
while(strcmp(name1,name2)!=0)
{
j++;
printf("input again:");
printf("j=%d\n",j);
gets(name1);
if(j>=3)
{
printf("超过次数!");
getch();
exit(0);
}
}
/*if (strcmp(name1,name2)!=0)
printf("wrong!\n");
else*/
printf("hi,welcome!");
j=0;
do{
printf("\ninput your password:\n");
pw=getPasswd();
//printf("\n");
j++;
fflush(stdin);
if(j>=3)
{
printf("超过次数!");
getch();
exit(0);
}
}while(strcmp(pw,PASS)!=0);
/*if (strcmp(pw,PASS)!=0)
printf("\nwrong!\n");
else*/
printf("\nhello!\n");
getch();
}