Ⅰ c语言编写一个用户登陆的程序
代码如下:
#include<stdio.h>
#pragma warning(disable:4996)
#include<string.h>
int main()
{
int i = 0;
char password[10] = { 0 };
printf("请输入密码:");
while (i < 3)
{
scanf("%s", password);
printf(" ");
if (strcmp(password, "972816") == 0)
{
printf("登录成功 ");
break;
}
else
{
i++;
if (i != 3)
printf("再输入一次");
}
}
if (i == 3)
printf("密码错误三次退出登录界面 ");
system("pause");
return 0;
(1)c语言银行登录页面程序扩展阅读:
#include后面有两种方式,<>;和""前者先在标准库中查找,查找不到在path中查找。后者为文件路径,若直接是文件名则在项目根目录下查找。
引用方法:#include<stdio.h>
注意事项:在TC2.0中,允许不引用此头文件而直接调用其中的函数,但这种做法是不标准的。也不建议这样做。以避免出现在其他IDE中无法编译或执行的问题。
Ⅱ C语言银行管理系统
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
char cFile[] = "date.txt";
struct bank
{
char id[10+1];
char psw[6+1];
double money;
};
welcome1()
{
printf("\n\n\t\t欢迎使用虚拟银行自动取款机服务!\t\t\n\n");
printf("请选择功能:\n");
printf("\n=================================================\n");
printf(" || 请输入序号 ||\n");
printf(" || 1.新用户开户。 ||\n");
printf(" || 2.老用户登陆。 ||\n");
printf(" || 3.退出系统。 ||\n");
printf("=================================================\n");
}
welcome2()
{
printf("\n\n\t\t注册须知\n\n");
printf("**************************************************\n");
printf("* 1.请填写您的真实资料! *\n");
printf("* 2.开户首期必须存入100元以上 *\n");
printf("**************************************************\n");
}
welcome3()
{
printf("\n\n\t\t\3 欢迎进入虚拟银行系统 \3\n\n");
printf("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n");
printf("\1\1\t 请选择功能:1.取款(最多透资2000); \1\1\n");
printf("\1\1\t 2.存款; \1\1\n");
printf("\1\1\t 3.查询余额; \1\1\n");
printf("\1\1\t 4.修改密码; \1\1\n");
printf("\1\1\t 5.返回主页面; \1\1\n");
printf("\1\1\t 任意键退出. \1\1\n");
printf("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n");
}
int search(char* user, char* pwd, char* real_pwd)/*判断帐号是否相同,不相同返回1*/
{
FILE* file;
char user_buff[256], pwd_buff[256];
file = fopen(cFile, "r");
if (!file) return 0;
while (!feof(file))
{
if (fscanf(file, "%s%s\n", user_buff, pwd_buff) == EOF) return 0;
if (!strcmp(user_buff, user))
{
if (real_pwd) strcpy(real_pwd, pwd_buff);
return 1;
}
}
fclose(file);
return 0;
}
int add(char* user, char* pwd, double coin_n)
{
FILE* file;
file = fopen(cFile, "a");
if (!file) return 0;
fprintf(file, "%s %s %.2lf\n", user, pwd, coin_n);
fclose(file);
return 0;
}
int wenjian(char* user, char* pwd,double coin)
{
if (search(user, pwd, NULL)) return 0;
else add(user, pwd, coin);
return 1;
}
zhuce()/*注册*/
{
struct bank *p;
int i=0,k=0,judge1,judge2;
char name[30];
char sex,ch;
char sh[18];
int n;
p=(struct bank*)malloc(sizeof(struct bank));/*给p分配内存*/
welcome2();
printf("请输入您的名字(纯英文):");
gets(name);
printf("请输入您的性别(男:1 女2):");
fflush(stdin);
scanf("%c",&sex);
fflush(stdin);
printf("请输入您的身份证号码:");
gets(sh);
for(n=0;n<strlen(name);n++)/*判断输入信息是否正确*/
{
if(name[n]>='0'&&name[n]<='9')
{
printf("您输入的名字有误!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
}
if(sex!='1'&&sex!='2')/*判断输入信息是否正确*/
{
printf("您输入的性别不对!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
if(strlen(sh)!=18)/*判断输入信息是否正确*/
{
printf("您输入的身份证号码不全!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
for(n=0;n<strlen(sh)-1;n++)/*判断输入信息是否正确*/
{
if(sh[n]<48||sh[n]>57)
{
printf("您输入的身份证号码非法!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
else
{
if(sh[18]!='x'&&sh[18]<48&&sh[18]>57)
{
printf("您输入的身份证号码非法!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
}
}
printf("请输入您的帐号(10位纯数字):\n");
fflush(stdin);
scanf("%s",p->id);
fflush(stdin);
while(i <strlen(p->id))
{
if((p->id[i] < 48) || (p->id[i] > 57))
{
judge1=0;
}
i++;
}
while(strlen(p->id)!=10 ||judge1==0)/*判断帐号的正确性*/
{
printf("您输入的帐号不正确,必须为10位纯数字!");
printf("请重新输入(10位纯数字):");
fflush(stdin);
scanf("%s",p->id);
fflush(stdin);
}
printf("请输入您的密码(6位纯数字):\n");
fflush(stdin);
scanf("%s",p->psw);
fflush(stdin);
while(k <strlen(p->psw))
{
if((p->psw[k] < 48) || (p->psw[k] > 57))
{
judge2=0;
}
k++;
}
while(strlen(p->psw)!=6 ||judge2==0)/*判断密码形式的正确性*/
{
printf("您输入不正确!密码必须为6位纯数字!\n");
printf("请重新输入密码(6位纯数字):");
fflush(stdin);
scanf("%s",p->psw);
fflush(stdin);
}
printf("请输入您的首期存款:");
fflush(stdin);
scanf("%lf",&p->money);
fflush(stdin);
while((p->money)<100)
{
printf("您必须存入100元以上,请重新输入:");
fflush(stdin);
scanf("%lf",&p->money);
fflush(stdin);
}
if (wenjian(p->id,p->psw,p->money))/*存入文件并输出基本信息*/
{
system("cls");
printf("注册成功!");
printf("您的注册信息如下,请牢记:\n");
printf("名字:");
puts(name);
printf("性别代码:%c\n",sex);
printf("身份证号码:");
puts(sh);
printf("帐号:");
puts(p->id);
printf("密码:");
puts(p->psw);
printf("您帐户里的余额为:%.2lf\n",p->money);
printf("请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
else/*如有相同帐号,注册失败*/
{
system("cls");
printf("您输入的帐号已经存在!注册失败!\n");
printf("请选择:按1返回主页面. 按任意键退出:");
scanf("%c",&ch);
if(ch=='1'){system("cls");main();}
else exit(0);
}
}
gongneng(char Account[10+1],char Password[6+1],double Money)/*登陆成功后的功能界面*/
{
FILE *ps;
struct bank xin[1000];
int k=0,b=0;
char mima[6+1],Chiose,x;
char count[10+1],word[6+1];
double inmoney,outmoney,addmoney;
welcome3();
fflush(stdin);
scanf("%c",&Chiose);
fflush(stdin);
ps=fopen(cFile,"r");
if (!ps)
{
printf("不能打开文件!按任意键退出!");
fflush(stdin);
scanf("%c",&x);
fflush(stdin);
exit(0);
}
if(Chiose=='1')
{
printf("输入您的取款金额:");
fflush(stdin);
scanf("%lf",&outmoney);
fflush(stdin);
while(!feof(ps))
{
fscanf(ps, "%s %s %lf",&xin[k].id,&xin[k].psw,&xin[k].money);
k++;
}
fclose(ps);
ps=fopen(cFile,"wb");
if (!ps)
{
printf("不能打开文件!按任意键退出!");
fflush(stdin);
scanf("%c",&x);
fflush(stdin);
exit(0);
}
while(!feof(ps))
{
//printf("%s %s %.2lf\n",xin[b].id,xin[b].psw,xin[b].money);
if ((strcmp(Account, xin[b].id)==0)&&(strcmp(Password, xin[b].psw)==0))
{
xin[b].money=xin[b].money-outmoney;
}
printf("%.2lf\n",xin[b].money);
fprintf(ps, "%s %s %.2lf\n", xin[b].id, xin[b].psw, xin[b].money);
b++;
}
}
}
denglu()/*登陆*/
{
FILE *fp;
char account[10+ 1],password[6 + 1],h;
int m=0;
char real_account[10+ 1]; /* 帐号缓存 */
char real_password[6 + 1]; /* 密码缓存*/
double real_money_o=0.0; /*存款缓存*/
printf("请输入您的帐号(10位纯数字):");
gets(account);
printf("请输入您的密码(6位纯数字):");
gets(password);
fp = fopen(cFile, "r");
if (!fp)
{
printf("不能打开文件!按任意键退出!");
fflush(stdin);
scanf("%c",&h);
fflush(stdin);
exit(0);
}
while (m<=2) /*判断是否输入错3次了*/
{
while(fscanf(fp, "%s %s %lf", &real_account, &real_password,&real_money_o) != EOF) /*循环判断帐号密码*/
{
if ((strcmp(real_account, account)==0)&&(strcmp(real_password, password)==0))
{
system("cls");
printf("登陆成功!");
gongneng(real_account,real_password,real_money_o);
fclose(fp);
return 0;
}
}
rewind(fp); /*重新打开文件,进行新一轮的密码验证*/
printf("您输入的帐号不存在或密码不正确!\n请重新输入:\n");
m++;
printf("请输入您的帐号(10位纯数字):");
fflush(stdin);
gets(account);
fflush(stdin);
printf("请输入您的密码(6位纯数字):");
fflush(stdin);
gets(password);
fflush(stdin);
}
fclose(fp);
printf("您输入帐号密码不正确已经3次,您被强制退出系统(按任意键退出)!");
fflush(stdin);
scanf("%c",&h);
fflush(stdin);
exit(0);
}
int main()
{
char chiose;
welcome1();
scanf("%c",&chiose);
getchar();
if(chiose <='0' ||chiose>='4')
{
while(chiose <='0' || chiose>='4')
{
printf("您的输入有误,请重新输入:");
scanf("%c",&chiose);
getchar();
}
}
if(chiose=='1')
{
system("cls");
zhuce();/*注册*/
}
if(chiose=='2')
{
system("cls");
denglu();/*登陆*/
}
if(chiose=='3')
{
printf("谢谢您的使用!");
exit(0);
}
}
打字不易,如满意,望采纳。
Ⅲ c语言 银行账户信息管理系统
#include <conio.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
char cFile[] = "date.txt";
struct bank
{
char id[10+1];
char psw[6+1];
double money;
};
welcome1()
{
printf("\n\n\t\t欢迎使用虚拟银行自动取款机服务!\t\t\n\n");
printf("请选择功能:\n");
printf("\n=================================================\n");
printf(" || 请输入序号 ||\n");
printf(" || 1.新用户开户。 ||\n");
printf(" || 2.老用户登陆。 ||\n");
printf(" || 3.退出系统。 ||\n");
printf("=================================================\n");
}
welcome2()
{
printf("\n\n\t\t注册须知\n\n");
printf("**************************************************\n");
printf("* 1.请填写您的真实资料! *\n");
printf("* 2.开户首期必须存入100元以上 *\n");
printf("**************************************************\n");
}
welcome3()
{
printf("\n\n\t\t\3 欢迎进入虚拟银行系统 \3\n\n");
printf("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n");
printf("\1\1\t 请选择功能:1.取款(最多透资2000); \1\1\n");
printf("\1\1\t 2.存款; \1\1\n");
printf("\1\1\t 3.查询余额; \1\1\n");
printf("\1\1\t 4.修改密码; \1\1\n");
printf("\1\1\t 5.返回主页面; \1\1\n");
printf("\1\1\t 任意键退出. \1\1\n");
printf("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\n");
}
int search(char* user, char* pwd, char* real_pwd)/*判断帐号是否相同,不相同返回1*/
{
FILE* file;
char user_buff[256], pwd_buff[256];
file = fopen(cFile, "r");
if (!file) return 0;
while (!feof(file))
{
if (fscanf(file, "%s%s\n", user_buff, pwd_buff) == EOF) return 0;
if (!strcmp(user_buff, user))
{
if (real_pwd) strcpy(real_pwd, pwd_buff);
return 1;
}
}
fclose(file);
return 0;
}
int add(char* user, char* pwd, double coin_n)
{
FILE* file;
file = fopen(cFile, "a");
if (!file) return 0;
fprintf(file, "%s %s %.2lf\n", user, pwd, coin_n);
fclose(file);
return 0;
}
int wenjian(char* user, char* pwd,double coin)
{
if (search(user, pwd, NULL)) return 0;
else add(user, pwd, coin);
return 1;
}
zhuce()/*注册*/
{
struct bank *p;
int i=0,k=0,judge1,judge2;
char name[30];
char sex,ch;
char sh[18];
int n;
p=(struct bank*)malloc(sizeof(struct bank));/*给p分配内存*/
welcome2();
printf("请输入您的名字(纯英文):");
gets(name);
printf("请输入您的性别(男:1 女2):");
fflush(stdin);
scanf("%c",&sex);
fflush(stdin);
printf("请输入您的身份证号码:");
gets(sh);
for(n=0;n<strlen(name);n++)/*判断输入信息是否正确*/
{
if(name[n]>='0'&&name[n]<='9')
{
printf("您输入的名字有误!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
}
if(sex!='1'&&sex!='2')/*判断输入信息是否正确*/
{
printf("您输入的性别不对!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
if(strlen(sh)!=18)/*判断输入信息是否正确*/
{
printf("您输入的身份证号码不全!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
for(n=0;n<strlen(sh)-1;n++)/*判断输入信息是否正确*/
{
if(sh[n]<48||sh[n]>57)
{
printf("您输入的身份证号码非法!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
else
{
if(sh[18]!='x'&&sh[18]<48&&sh[18]>57)
{
printf("您输入的身份证号码非法!\n");
printf("\n请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
}
}
printf("请输入您的帐号(10位纯数字):\n");
fflush(stdin);
scanf("%s",p->id);
fflush(stdin);
while(i <strlen(p->id))
{
if((p->id[i] < 48) || (p->id[i] > 57))
{
judge1=0;
}
i++;
}
while(strlen(p->id)!=10 ||judge1==0)/*判断帐号的正确性*/
{
printf("您输入的帐号不正确,必须为10位纯数字!");
printf("请重新输入(10位纯数字):");
fflush(stdin);
scanf("%s",p->id);
fflush(stdin);
}
printf("请输入您的密码(6位纯数字):\n");
fflush(stdin);
scanf("%s",p->psw);
fflush(stdin);
while(k <strlen(p->psw))
{
if((p->psw[k] < 48) || (p->psw[k] > 57))
{
judge2=0;
}
k++;
}
while(strlen(p->psw)!=6 ||judge2==0)/*判断密码形式的正确性*/
{
printf("您输入不正确!密码必须为6位纯数字!\n");
printf("请重新输入密码(6位纯数字):");
fflush(stdin);
scanf("%s",p->psw);
fflush(stdin);
}
printf("请输入您的首期存款:");
fflush(stdin);
scanf("%lf",&p->money);
fflush(stdin);
while((p->money)<100)
{
printf("您必须存入100元以上,请重新输入:");
fflush(stdin);
scanf("%lf",&p->money);
fflush(stdin);
}
if (wenjian(p->id,p->psw,p->money))/*存入文件并输出基本信息*/
{
system("cls");
printf("注册成功!");
printf("您的注册信息如下,请牢记:\n");
printf("名字:");
puts(name);
printf("性别代码:%c\n",sex);
printf("身份证号码:");
puts(sh);
printf("帐号:");
puts(p->id);
printf("密码:");
puts(p->psw);
printf("您帐户里的余额为:%.2lf\n",p->money);
printf("请选择:按1返回主页面. 按任意键退出:");
fflush(stdin);
scanf("%c",&ch);
fflush(stdin);
if(ch=='1'){system("cls");main();}
else exit(0);
}
else/*如有相同帐号,注册失败*/
{
system("cls");
printf("您输入的帐号已经存在!注册失败!\n");
printf("请选择:按1返回主页面. 按任意键退出:");
scanf("%c",&ch);
if(ch=='1'){system("cls");main();}
else exit(0);
}
}
gongneng(char Account[10+1],char Password[6+1],double Money)/*登陆成功后的功能界面*/
{
FILE *ps;
struct bank xin[1000];
int k=0,b=0;
char mima[6+1],Chiose,x;
char count[10+1],word[6+1];
double inmoney,outmoney,addmoney;
welcome3();
fflush(stdin);
scanf("%c",&Chiose);
fflush(stdin);
ps=fopen(cFile,"r");
if (!ps)
{
printf("不能打开文件!按任意键退出!");
fflush(stdin);
scanf("%c",&x);
fflush(stdin);
exit(0);
}
if(Chiose=='1')
{
printf("输入您的取款金额:");
fflush(stdin);
scanf("%lf",&outmoney);
fflush(stdin);
while(!feof(ps))
{
fscanf(ps, "%s %s %lf",&xin[k].id,&xin[k].psw,&xin[k].money);
k++;
}
fclose(ps);
ps=fopen(cFile,"wb");
if (!ps)
{
printf("不能打开文件!按任意键退出!");
fflush(stdin);
scanf("%c",&x);
fflush(stdin);
exit(0);
}
while(!feof(ps))
{
//printf("%s %s %.2lf\n",xin[b].id,xin[b].psw,xin[b].money);
if ((strcmp(Account, xin[b].id)==0)&&(strcmp(Password, xin[b].psw)==0))
{
xin[b].money=xin[b].money-outmoney;
}
printf("%.2lf\n",xin[b].money);
fprintf(ps, "%s %s %.2lf\n", xin[b].id, xin[b].psw, xin[b].money);
b++;
}
}
}
denglu()/*登陆*/
{
FILE *fp;
char account[10+ 1],password[6 + 1],h;
int m=0;
char real_account[10+ 1]; /* 帐号缓存 */
char real_password[6 + 1]; /* 密码缓存*/
double real_money_o=0.0; /*存款缓存*/
printf("请输入您的帐号(10位纯数字):");
gets(account);
printf("请输入您的密码(6位纯数字):");
gets(password);
fp = fopen(cFile, "r");
if (!fp)
{
printf("不能打开文件!按任意键退出!");
fflush(stdin);
scanf("%c",&h);
fflush(stdin);
exit(0);
}
while (m<=2) /*判断是否输入错3次了*/
{
while(fscanf(fp, "%s %s %lf", &real_account, &real_password,&real_money_o) != EOF) /*循环判断帐号密码*/
{
if ((strcmp(real_account, account)==0)&&(strcmp(real_password, password)==0))
{
system("cls");
printf("登陆成功!");
gongneng(real_account,real_password,real_money_o);
fclose(fp);
return 0;
}
}
rewind(fp); /*重新打开文件,进行新一轮的密码验证*/
printf("您输入的帐号不存在或密码不正确!\n请重新输入:\n");
m++;
printf("请输入您的帐号(10位纯数字):");
fflush(stdin);
gets(account);
fflush(stdin);
printf("请输入您的密码(6位纯数字):");
fflush(stdin);
gets(password);
fflush(stdin);
}
fclose(fp);
printf("您输入帐号密码不正确已经3次,您被强制退出系统(按任意键退出)!");
fflush(stdin);
scanf("%c",&h);
fflush(stdin);
exit(0);
}
int main()
{
char chiose;
welcome1();
scanf("%c",&chiose);
getchar();
if(chiose <='0' ||chiose>='4')
{
while(chiose <='0' || chiose>='4')
{
printf("您的输入有误,请重新输入:");
scanf("%c",&chiose);
getchar();
}
}
if(chiose=='1')
{
system("cls");
zhuce();/*注册*/
}
if(chiose=='2')
{
system("cls");
denglu();/*登陆*/
}
if(chiose=='3')
{
printf("谢谢您的使用!");
exit(0);
}
}
Ⅳ c语言银行管理系统初学者,求代码不要太难,简单写一下代码
if (codeInput != code) {
printf("wrong input, try again");
InputCode();
}
else {
login();
}
Ⅳ c语言编写用户登录程序
代码如下:
#include<stdio.h>
#pragma warning(disable:4996)
#include<string.h>
int main()
{
int i = 0;
char password[10] = { 0 };
printf("请输入密码:");
while (i < 3)
{
scanf("%s", password);
printf(" ");
if (strcmp(password, "972816") == 0)
{
printf("登录成功 ");
break;
}
else
{
i++;
if (i != 3)
printf("再输入一次");
}
}
if (i == 3)
printf("密码错误三次退出登录界面 ");
system("pause");
return 0;
(5)c语言银行登录页面程序扩展阅读:
#include后面有两种方式,<>;和""前者先在标准库中查找,查找不到在path中查找。后者为文件路径,若直接是文件名则在项目根目录下查找。
引用方法:#include<stdio.h>
注意事项:在TC2.0中,允许不引用此头文件而直接调用其中的函数,但这种做法是不标准的。也不建议这样做。以避免出现在其他IDE中无法编译或执行的问题。
Ⅵ 怎么用C语言编写简单的登录程序
#include <stdio.h> int main() { int i, a=1234567890, b; for(i=0;;) { printf("输入密码:"); scanf("%d",&b); if(b==a) { printf("密码正确!\n"); break; } else { prinf("密码错误,重新输入!\n\n"); i++; } } return 0; }
Ⅶ C语言编写用户登录程序
艾达的小刀
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
/*随机码产生函数*/
void RandomCode (char Rcode[])
{
int i;
srand ((unsigned int)time(NULL));
for (i = 0; i < 3; ++i)
Rcode[i] = rand()%10 + '0';
Rcode[i] = '\0';
}
/*登陆函数,判断信息是否匹配,若匹配返回1,否则返回0*/
int LandedApp (char *password[], char Rcode[])
{
char name[10] = {0};
char pword[10] = {0};
char rcode[4] = {0};
printf ("用户名 : ");
gets (name);
printf ("密码 : ");
gets (pword);
printf ("随机码 : ");
gets (rcode);
if (strcmp (name, password[0]) != 0 || strcmp (pword, password[1]) != 0 || strcmp (rcode, Rcode) != 0)
return 0;
else
return 1;
}
int main ()
{
char * password[2] = {"admin", "admin123"}; //用户名和密码
char rc[4] = {0}; //随机码
int count = 3; //可输入次数
puts ("请输入用户名,密码和随机码:");
while (count)
{
RandomCode (rc);
printf ("随机码 : %s\n", rc);
if (LandedApp(password, rc) != 0)
break;
--count;
if (count != 0)
puts ("错误的用户名或密码或随机码,请重新输入: ");
}
if (count != 0)
puts ("\n成功登陆!");
else
puts ("\n登录失败 !");
return 0;
}
艾达的小刀
Ⅷ 用c语言模拟银行账号密码登录,那个大神可以指导一下
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
intchcode(){
charpw[50],ch;
char*syspw="abc";//原始密码
inti,m=0;
printf("请输入密码:");
while(m<3){
i=0;
while((ch=_getch())!=' '){
if(ch==''&&i>0){
printf("");
--i;
}
elseif(ch!=''){
pw[i++]=ch;
printf("*");
}
}
pw[i]='