本文目录一览:
- 1、c语言 银行账户信息管理系统
- 2、C语言怎样设置特定的密码帐号登录系统?
- 3、用C语言编写银行帐户账户管理系统
- 4、C语言用户登录系统账户密码比对
- 5、C语言用字符串比较函数验证账号和密码?
- 6、c语言编写注册与登录的程序
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;nstrlen(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;nstrlen(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]48sh[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语言怎样设置特定的密码帐号登录系统?
首先需要确定使用的是那种编译环境,如turbo C,Unix C还是VC,然后在选用编译器提供的合适的API函数,这样才能达到事半功倍的效果,写出高效率的代码。不过,不管是基于那种编程环境,基本思路是一样的,就是通过字符串读取函数gets()从客户端(命令窗口或对话框)读取用户输入的用户名和密码,然后与设置好的用户名和密码分别进行比较(可以采用字符串比较函数strcmp()),比较结果为真,则用户名和密码匹配,从登陆界面切换到执行界面,否则,提示错误。
用C语言编写银行帐户账户管理系统
使用 C 语言编写一个银行帐户管理系统?你的这个编程要求实在是太高了,肯定是不会有人满足你的要求的。
因为这个要求已经不是简单地答疑 C 语言的语法错误之类的问题了,而是需要从头设计整个该帐户管理系统的各种数据存储结构、以及各种算法(在编写此软件的过程中,肯定需要涉及:到底采用哪一种排序算法效率最高、以及采取哪一种查找算法对人员进行查询效率最高),并且要想彻底从编写一个源程序,到编译、链接、直到该应用软件能够运行出用户所要求的最终正确结果,那是需要花费很多的时间和精力去调试的,而不是只要写出程序代码,即使程序的编程思路是正确的,也不一定能够保证程序的运行结果是正确的。
C语言用户登录系统账户密码比对
#include stdio.h
#include string.h
typedef struct account{
char name[32];
char acc[16];
char psw[16];
}Acc;
// data是结构体数组,filename是文件绝对地址,n保存读入的结构体数量
void GetDataFromTxt(Acc* data, const char* filename, int* n)
{
FILE *fp = fopen(filename, “r”);
if( NULL == fp ){
printf(“Open file failed or no this file!\n”);
return;
}
int i = 0;
while( !feof(fp) )
{
fscanf(fp, “%s %s %s”, data[i].name, data[i].acc, data[i].psw);
i++;
}
*n = i;
}
int main()
{
int i, n;
Acc data[100];
// 获取数据
GetDataFromTxt(data, “E:\\secret.txt”, n);
printf(“n = %d\n”, n);
printf(“姓名 账号 密码\n”);
for(i = 0; i n; ++i)
printf(“%-4s %-16s %-10s\n”, data[i].name, data[i].acc, data[i].psw);
// 登录示例
putchar(‘\n’);
char acc[16], psw[16];
do{
// 这里只是粗略地写了一个
// 具体的账号错误或者密码错误自行发挥
printf(“请输入账号:”);
scanf(“%s”, acc);
printf(“请输入密码:”);
scanf(“%s”, psw);
for(i = 0; i n; ++i)
{
if( strcmp(acc,data[i].acc)==0 strcmp(psw,data[i].psw)==0 ){
printf(“登陆成功!\n”);
break;
}
}
if( i == n ){
printf(“账号或密码不正确!请重新输入!\n\n”);
}else{
break;
}
}while(1);
printf(“Bye bye!!!\n”);
return 0;
}
C语言用字符串比较函数验证账号和密码?
#include string.h
char user[]=”输入的帐号”, pwd[]=”输入的密码”;
if (strcmp(“真实帐号”, user) == 0 strcmp(“对应密码”, pwd) == 0) {
printf(“验证成功!”);
} else {
printf(“帐号或密码错误!”);
}
c语言编写注册与登录的程序
希望对你有所帮助
#includestdio.h
#includestdlib.h
#includestring.h
#includectype.h
#define N 100
struct user
{
int user_id;
char user_name[19];//最大18位
char password[13];//最大13位
char like[255];
char sign[255];
};
/*
* 验证用户名长度是否合法
*/
int length_user_name(char *p)
{
int l;
l=strlen(p);
if(l18||l1)
{
return 0;
}
else
return l;
}
/*
* 判断用户名是否有效
*/
int valid_user_name(char *p)
{
int i=0;
int len = strlen(p);
if((*p = ‘a’ *p = ‘z’) || (*p = ‘A’ *p =’Z’)) //判断首字符是不是字母
{
for(i = 0; i len; i++)
{
if(!(p[i] == ‘_’ || (p[i] = ‘a’ p[i] = ‘z’) || (p[i] = ‘A’ p[i] =’Z’)
||(p[i] =’0′ p[i] = ‘9’))) //判断后面字符是否有效
return 0;
}
return 1;
}
else
return 0;
}
/*
* 判断用户名是否有效
*/
int is_username_valid(char *p)
{
if((*p = ‘a’ *p = ‘z’) || (*p = ‘A’ *p =’Z’))
{
p++;
while(*p)
{
if(!(isalpha(*p) || *p == ‘_’ || isdigit(*p)))
return 0;
p++;
}
return 1;
}
else
{
return 0;
}
}
/*
* 密码长度有效性验证
*/
int length_password(char *p)
{
int len;
len = strlen(p);
if(len6||len12)
{
return 0;
}
else
return len;
}
/*
* 密码的有效性验证
*/
int is_password_valid(char *p)
{
int i=0;
for(;*p != ‘\0’; p++)
{
if(!( (*p = ‘a’ *p = ‘z’) || (*p = ‘A’ *p =’Z’)
||(*p =’0′ *p = ‘9’))) //判断字符是否有效
return 0;
}
return 1;
}
int two_password_valid(char *p1,char*p2)
{
if(strcmp(p1,p2)==0)
return 1;
else
return 0;
}
/*
* 完成注册功能
*/
int user_register(struct user *ptr_user,int size)
{
char password[13];
char repassword[13];
if(size==N)
{
puts(“注册人数以满!”);
return 0;
}
printf(“请输入注册姓名:”);
fflush(stdin);
gets(ptr_user[size].user_name);
if(!(length_user_name(ptr_user[size].user_name)valid_user_name(ptr_user[size].user_name)))
{
printf(“您输入的姓名无效,用户名在1-18之间,首字符为字母,后面必须为字母,数字或下划线!!!”);
return 0;
}
printf(“请输入注册密码:”);
fflush(stdin);
gets(password);
printf(“请再次输入注册密码:”);
fflush(stdin);
gets(repassword);
if(!two_password_valid(password,repassword))
{
printf(“\n两次输入的密码不一致!”);
return 0;
}
else
{
strcpy(ptr_user[size].password,password);
}
if(!(length_password(ptr_user[size].password)is_password_valid(ptr_user[size].password)))
{
printf(“您输入的密码无效,密码应在6-12之间,密码只能包含字母和数字!!!”);
return 0;
}
printf(“请输入您的爱好:”);
fflush(stdin);
gets(ptr_user[size].like);
printf(“请输入您的个性签名:”);
fflush(stdin);
gets(ptr_user[size].sign);
printf(“您的编号为:%d,这将是您的登陆帐号.”,ptr_user[size].user_id=10000+size);
return 1;
}
/*
* 如果登陆成功则返回第i+1个用户的信息,否则返回0
*/
int is_my_user(struct user *p,int size)
{
int i;
int zhanghu;
char mima[15];
printf(“请输入您的帐号: “);
scanf(“%d”,zhanghu);
fflush(stdin);
printf(“请输入您的密码: “);
gets(mima);
for(i=0;isize;i++)
{
if((zhanghu == p[i].user_id)(strcmp(mima,p[i].password)==0))
{
return i + 1;
}
}
return 0;
}
void display_user(struct user u)
{
printf(“\n你的帐号是:%d”,u.user_id);
printf(“\n你注册姓名是:%s”,u.user_name);
printf(“\n你的爱好:%s”,u.like);
printf(“\n你的个性签名:%s”,u.sign);
}
void update_password(struct user *ptr_user,int size)
{
char mima1[13],mima2[13];
int i = is_my_user(ptr_user,size);
if(i)
{
i–;
}
else
{
printf(“\n帐号密码不存在!”);
return;
}
printf(“请输入新密码: “);
scanf(“%s”,mima1);
printf(“请再次输入新密码: “);
scanf(“%s”,mima2);
if(two_password_valid(mima1,mima2) length_password(mima1) is_password_valid(mima1))
{
strcpy(ptr_user[i].password,mima1);//完成新旧密码的调换
printf(“\n您的的密码修改成功!”);
}
else
printf(“\您的密码修改失败!”);
}
//显示菜单
int show_menu()
{
int choice;
printf(“\n1.注册”);
printf(“\n2.登陆”);
printf(“\n3.修改密码”);
printf(“\n4.退出”);
printf(“\n请选择1-4\n”);
scanf(“%d”,choice);
return choice;
}
int main()
{
struct user our_users[N];
int count = 0;
int current_user;
while(1)
{
switch(show_menu())
{
case 1:
if(user_register(our_users,count))
{
count++;
printf(“\n注册成功!”);
}
break;
//注册
case 2:
if((current_user = is_my_user(our_users,count)))
{
printf(“\n登陆成功!”);
display_user(our_users[current_user – 1]);
}
else
printf(“\n登陆失败!”);
break;
//登陆
case 3:
update_password(our_users,count);
break;
//修改密码
case 4:
exit(1);
break;
//退出
default:
printf(“请正确输入”);
}
}
return 0;
}
原创文章,作者:小蓝,如若转载,请注明出处:https://www.506064.com/n/306099.html