此为本人大一期末作品,分享出来,供大家参考使用,由于当时刚学习编程,如有不足之处请谅解。
//用c语言写的简易注册登录系统(大一期末作品)
#include
#include
#include
#include
struct nap
{
char user[128];
char key[128];
};
struct nap change[128];
typedef int JUDGE;
typedef int LOOP;
int main()
{
int reg(void);
int landing(void);
char number;
do
{
printf("\n1.Register\http://doc.xuehai.netnding\nPlease choose the number(1 or 2):");
fflush(stdin);
scanf("%c",&number);
}while(number!='1'&&number!='2');
switch (number)
{
case '1':
reg(); break;
case '2':
landing();
}
system("pause");
return 0;
}
int reg(void)
{
int compare(char *,char *);
int increase(void);
void putIn(char *);
JUDGE turn,n=0;
char filePassword[9]={"12348888"},password[128];
char * p=password;
do
{
printf("\nPlease enter the administrator password:");
fflush(stdin);
putIn(p);
turn=compare(password,filePassword);
n++;
if(turn==0&&n<=3)
{
printf("\nWrong password!\nPlease enter again!\n");
}
else if(n>3)
{
printf("\nYou entered too many times!\n");
return 0;
}
}while(turn==0);
increase();
}
int compare(char * p,char * q)
{
while(*p!='\0'&&*q!='\0')
{
if(*p!=*q)
{
return 0;
}
else
{
p++;
q++;
}
}
if(*p==*q)
{
return 1;
}
return 0;
}
int increase(void)
{
void putIn(char *);
int catch(JUDGE);
int userLoopCompare(char *,int * h);
JUDGE i,n=0,m=0,j=1,h=0;
FILE * fp;
char tem[128],compar[128],*q=compar,* p=tem;
do
{
do
{
printf("\nPlease enter the user name:");
gets(p);
n++;
if(*p=='\0'&&n<=3)
{
printf("\nYou did not enter the user name,please enter again!\n");
}
else if(n>3)
{
printf("\nYou entered too many times!\n");
return 0;
}
}while(*p=='\0');
m=0;
p=p+strlen(tem);
*p='\n';
p++;
*p='\0';
p=tem;
catch(j);
i=userLoopCompare(p,&h);
m++;
if(i==0&&m<=3)
{
printf("\nThe user name has been registered!\nPlease enter again!\n");
}
else if(m>3)
{
printf("\nYou entered too many times!\n");
return 0;
}
}while(i==0);
p=p+strlen(tem);
if(*(p-2)=='\n')
{
p--;
}
n=0;
do
{
m=0;
do
{
m++;
printf("\nPlease enter the password:");
putIn(p);
if(*p=='\0'&&m<=3)
{
printf("\nYou did not enter the password!\nPlease enter again!\n");
}
else if(m>3)
{
printf("\nYou entered too many times!\n");
return 0;
}
}while(*p=='\0');
printf(&qu
ot;\nPlease enter the password again:");
putIn(q);
i=compare(p,q);
if(i==1)
{
p=tem;
}
else
{
n++;
if(n<=3)
{
printf("\