├── README.md ├── 银行用户管理系统 ├── Password.h ├── Revise_user.h ├── View.h ├── Delete_user.h ├── Read_file.h ├── Created_user.h ├── File_user.h ├── 银行用户信息操作管理系统.c ├── Query_user.h ├── Amend_password.h ├── Register.h └── Add_user.h └── 哈弗曼编码译码器 └── 哈弗曼编码译码器.c /README.md: -------------------------------------------------------------------------------- 1 | # C-program-Design 2 | C语言程序设计(小项目) 3 | -------------------------------------------------------------------------------- /银行用户管理系统/Password.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: 银行用户信息操作管理系统(密码登录).c 3 | > Author: 4 | > Mail: 5 | > Created Time: 2016年06月23日 星期四 17时23分31秒 6 | ************************************************************************/ 7 | void my_password() 8 | { 9 | int flag=0; 10 | char Tpassword[N]; 11 | char Ipassword[N]; 12 | char *password; 13 | FILE *fp; 14 | 15 | fp=fopen("银行系统登录文件","r+"); 16 | if(fp==NULL) 17 | { 18 | printf("文件打开失败\n"); 19 | exit(1); 20 | } 21 | 22 | password=Tpassword; 23 | 24 | fscanf(fp,"%s",password); 25 | 26 | printf("如要登录请先请输入登录密码:\n"); 27 | 28 | scanf("%s",Ipassword); 29 | 30 | while(getchar()!='\n') 31 | continue; 32 | 33 | while(flag==0) 34 | { 35 | if(strcmp(Ipassword,password)==0) 36 | { 37 | printf("\n正确!\n"); 38 | printf("按下任意键继续!\n"); 39 | 40 | flag=1; 41 | getchar(); 42 | } 43 | else 44 | { 45 | printf("错误!请再试一次!\n"); 46 | scanf("%s",Ipassword); 47 | 48 | while(getchar()!='\n') 49 | continue; 50 | } 51 | } 52 | 53 | fclose(fp); 54 | } 55 | -------------------------------------------------------------------------------- /银行用户管理系统/Revise_user.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: Revise_user.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2016年06月26日 星期日 14时33分09秒 6 | ************************************************************************/ 7 | 8 | Node *my_revise(Node *loop) 9 | { 10 | char bank_number[N]; 11 | Node *Phead; 12 | int number=0; 13 | 14 | loop=my_read_file(number); 15 | 16 | Phead=loop; 17 | 18 | if(loop==NULL) 19 | { 20 | printf("银行系统里面此时没有任何账户!\n"); 21 | printf("请按下任意键返回登录界面!\n"); 22 | 23 | getchar(); 24 | 25 | my_register_1(); 26 | } 27 | 28 | if(loop!=NULL) 29 | { 30 | printf("请输入您要修改的账户信息的银行卡号:\n"); 31 | 32 | scanf("%s",bank_number); 33 | 34 | while(strcmp(loop->information.Bank_number,bank_number)!=0) 35 | { 36 | loop=loop->next; 37 | } 38 | 39 | printf("请输入您现在要修改的账户信息!\n"); 40 | printf("请输入要修改的用户的姓名,性别,年龄,身份证号,银行卡号,要存的钱数,存储类型,存储时间(月):\n"); 41 | 42 | scanf("%s%s%d%s%s%d%s%d",loop->name,loop->sex,&loop->age,loop->ID_card,loop->information.Bank_number,\ 43 | &loop->information.start_money,loop->information.save_sort,&loop->information.month); 44 | 45 | printf("您成功的修改了用户的资料!\n\n"); 46 | printf("请按下任意键返回登录界面!\n"); 47 | 48 | while(getchar()!='\n') 49 | continue; 50 | 51 | getchar(); 52 | 53 | my_register_1(); 54 | } 55 | 56 | return Phead; 57 | } 58 | -------------------------------------------------------------------------------- /银行用户管理系统/View.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: View.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2016年06月23日 星期四 21时53分17秒 6 | ************************************************************************/ 7 | 8 | void my_view() 9 | { 10 | Node * loop; 11 | int number=0; 12 | loop=my_read_file(number); 13 | 14 | if(loop==NULL) 15 | { 16 | printf("银行系统里面没有用户信息!\n"); 17 | printf("请按下任意键返回到登陆界面!先给账户文件中添加新用户!\n"); 18 | 19 | while(getchar()!='\n') 20 | continue; 21 | 22 | getchar(); 23 | 24 | my_register_1(); 25 | } 26 | else 27 | { 28 | printf("======================================================================================================\n\n\n"); 29 | printf("姓名\t性别\t年龄\t身份证号\t银行卡号\t存钱数\t存储类别\t存储时间(月)\n\n\n"); 30 | 31 | for(;loop!=NULL;loop=loop->next) 32 | { 33 | printf("%s\t%s\t%d\t%s\t\t%s\t\t%d\t%s\t\t%d\n\n\n",loop->name,loop->sex,loop->age,loop->ID_card,\ 34 | loop->information.Bank_number,loop->information.start_money,loop->information.save_sort,loop->information.month); 35 | } 36 | 37 | printf("======================================================================================================\n\n\n"); 38 | printf("用户资料显示成功!请按下任意键返回到登陆界面!\n"); 39 | 40 | while(getchar()!='\n') 41 | continue; 42 | 43 | getchar(); 44 | 45 | my_register_1(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /银行用户管理系统/Delete_user.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: Delete_user.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2016年06月26日 星期日 15时33分27秒 6 | ************************************************************************/ 7 | 8 | Node *my_delete(Node *loop) 9 | { 10 | char bank_number[N]; 11 | int number=0; 12 | 13 | loop=my_read_file(number); 14 | 15 | Node *Phead,*pre; 16 | 17 | Phead=loop; 18 | pre=loop; 19 | 20 | if(loop==NULL) 21 | { 22 | printf("银行系统里面此时没有任何账户!\n"); 23 | printf("请按下任意键返回登陆界面!\n"); 24 | 25 | while(getchar()!='\n') 26 | continue; 27 | 28 | getchar(); 29 | 30 | my_register_1(); 31 | } 32 | 33 | if(loop!=NULL) 34 | { 35 | printf("请输入您要删除的账户的银行卡号:\n"); 36 | scanf("%s",bank_number); 37 | 38 | if(strcmp(Phead->information.Bank_number,bank_number)==0) 39 | { 40 | Phead=Phead->next; 41 | } 42 | else 43 | { 44 | while(strcmp(loop->information.Bank_number,bank_number)!=0) 45 | { 46 | pre=loop; 47 | loop=loop->next; 48 | } 49 | 50 | pre->next=loop->next; 51 | } 52 | 53 | printf("您成功的删除了指定的银行账户!\n"); 54 | printf("请按下任意键返回登陆界面!\n"); 55 | 56 | while(getchar()!='\n') 57 | continue; 58 | 59 | getchar(); 60 | 61 | my_register_1(); 62 | } 63 | 64 | return Phead; 65 | } 66 | -------------------------------------------------------------------------------- /银行用户管理系统/Read_file.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: Read_file.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2016年06月28日 星期二 12时53分00秒 6 | ************************************************************************/ 7 | 8 | Node *my_read_file(int number) 9 | { 10 | FILE *fp; 11 | char file_name[N]; 12 | Node *phead,*p,*q; 13 | 14 | phead=(Node *)malloc(sizeof(Node)); 15 | if(phead==NULL) 16 | exit(1); 17 | 18 | phead->next=NULL; 19 | p=phead; 20 | 21 | if(number==3) 22 | printf("请确认要添加的文件名:\n"); 23 | else 24 | printf("请输入要查找的文件名:\n"); 25 | 26 | scanf("%s",file_name); 27 | 28 | fp=fopen(file_name,"r"); 29 | 30 | if(fp==NULL) 31 | { 32 | printf("银行系统中没有这个账户文件!\n"); 33 | printf("按下任意键退出系统!然后登录系统先新建账户文件!\n"); 34 | 35 | while(getchar()!='\n') 36 | continue; 37 | 38 | getchar(); 39 | 40 | exit(1); 41 | } 42 | else 43 | { 44 | while(!feof(fp)) 45 | { 46 | q=(Node *)malloc(sizeof(Node)); 47 | if(q==NULL) 48 | exit(1); 49 | 50 | fscanf(fp,"%s\t%s\t%d\t%s\t%s\t%d\t%s\t%d\n",q->name,q->sex,&q->age,q->ID_card,q->information.Bank_number,\ 51 | &q->information.start_money,q->information.save_sort,&q->information.month); 52 | 53 | p->next=q; 54 | p=q; 55 | } 56 | 57 | if(q->age<=0||q->age>=130) 58 | { 59 | phead->next=NULL; 60 | } 61 | 62 | p->next=NULL; 63 | 64 | fclose(fp); 65 | 66 | return phead->next; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /银行用户管理系统/Created_user.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: Created.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2016年06月24日 星期五 16时08分00秒 6 | ************************************************************************/ 7 | 8 | Node *created_user() 9 | { 10 | Node *p,*q,*phead=NULL; 11 | int i; 12 | int number; 13 | 14 | printf("请输入您要创建的用户数:\n"); 15 | scanf("%d",&number); 16 | 17 | while(number<=0) 18 | { 19 | printf("请输入用户数大于0!请再输入一次!\n"); 20 | scanf("%d",&number); 21 | } 22 | 23 | if(number>0) 24 | { 25 | printf("请输入要创建的用户的姓名,性别,年龄,身份证号,银行卡号,要存的钱数,存储类型,存储时间(月):\n"); 26 | p=(Node *)malloc(sizeof(Node)); 27 | if(p==NULL) 28 | exit(1); 29 | 30 | scanf("%s%s%d%s%s%d%s%d",p->name,p->sex,&p->age,p->ID_card,p->information.Bank_number,&p->\ 31 | information.start_money,p->information.save_sort,&p->information.month); 32 | 33 | p->next=NULL; 34 | phead=p; 35 | 36 | for(i=0;iname,q->sex,&q->age,q->ID_card,q->information.Bank_number,&q->\ 43 | information.start_money,q->information.save_sort,&q->information.month); 44 | 45 | q->next=NULL; 46 | p->next=q; 47 | p=q; 48 | } 49 | 50 | printf("您成功的创建了%d个用户的资料!\n\n",number); 51 | } 52 | 53 | printf("请按下任意键返回登陆界面!\n"); 54 | 55 | while(getchar()!='\n') 56 | continue; 57 | 58 | getchar(); 59 | 60 | my_register_1(); 61 | 62 | return phead; 63 | } 64 | -------------------------------------------------------------------------------- /银行用户管理系统/File_user.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: File_user.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2016年06月27日 星期一 22时08分11秒 6 | ************************************************************************/ 7 | 8 | void my_file(Node *loop) 9 | { 10 | 11 | char fp_name[N]; 12 | FILE *fp_save; 13 | printf("请输入您要保存的文件名:\n"); 14 | 15 | scanf("%s",fp_name); 16 | 17 | fp_save=fopen(fp_name,"wt+"); 18 | 19 | if(fp_save==NULL) 20 | { 21 | printf("文件创建或打开失败!\n"); 22 | printf("请按下任意键返回到登录界面!\n"); 23 | 24 | while(getchar()!='\n') 25 | continue; 26 | 27 | getchar(); 28 | 29 | my_register_1(); 30 | } 31 | 32 | else 33 | { 34 | if(loop==NULL) 35 | { 36 | printf("账户文件创建成功,但此时系统中没有可保存的用户资料!\n"); 37 | printf("请按下任意键返回到登录界面!\n"); 38 | 39 | while(getchar()!='\n') 40 | continue; 41 | 42 | getchar(); 43 | 44 | my_register_1(); 45 | } 46 | else 47 | { 48 | while(loop!=NULL) 49 | { 50 | fprintf(fp_save,"%s\t%s\t%d\t%s\t\t%s\t\t%d\t%s\t\t%d\n",loop->name,loop->sex,loop->age,\ 51 | loop->ID_card,loop->information.Bank_number,loop->information.start_money,\ 52 | loop->information.save_sort,loop->information.month); 53 | 54 | loop=loop->next; 55 | } 56 | printf("账户资料已成功保存到磁盘文件中!\n"); 57 | printf("请按下任意键返回到登录界面!\n"); 58 | 59 | while(getchar()!='\n') 60 | continue; 61 | 62 | getchar(); 63 | 64 | my_register_1(); 65 | } 66 | } 67 | fclose(fp_save); 68 | } 69 | -------------------------------------------------------------------------------- /银行用户管理系统/银行用户信息操作管理系统.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: 银行用户信息操作管理系统.c 3 | > Author: 4 | > Mail: 5 | > Created Time: 2016年06月23日 星期四 18时03分24秒 6 | ************************************************************************/ 7 | 8 | #include 9 | #include 10 | #include 11 | #define N 30 12 | 13 | struct storage{ 14 | char Bank_number[N];//银行卡号 15 | int start_money; 16 | char save_sort[N];//存的类别 17 | int month; 18 | }; 19 | 20 | typedef struct node{ 21 | char name[N]; 22 | char sex[N]; 23 | int age; 24 | char ID_card[N]; 25 | struct storage information; 26 | struct node *next; 27 | }Node; 28 | 29 | #include"Register.h" 30 | #include"Password.h" 31 | #include"Read_file.h" 32 | #include"Amend_password.h" 33 | #include"Created_user.h" 34 | #include"Add_user.h" 35 | #include"Revise_user.h" 36 | #include"Delete_user.h" 37 | #include"Query_user.h" 38 | #include"File_user.h" 39 | #include"View.h" 40 | 41 | int main() 42 | { 43 | int figure; 44 | Node *mid=NULL; 45 | 46 | my_password(); 47 | my_register_1(); 48 | 49 | while(1) 50 | { 51 | 52 | if(scanf("%d",&figure)==1) 53 | { 54 | 55 | while(getchar()!='\n') 56 | continue; 57 | 58 | switch(figure) 59 | { 60 | case 1:my_view();break; 61 | 62 | case 2:mid=created_user();break; 63 | 64 | case 3:mid=my_trade(figure);break; 65 | 66 | case 4:mid=my_revise(mid);break; 67 | 68 | case 5:mid=my_delete(mid);break; 69 | 70 | case 6:my_query(mid);break; 71 | 72 | case 7:my_file(mid);break; 73 | 74 | case 8:my_amend_password();break; 75 | 76 | default:printf("退出系统!\n");exit(0);break; 77 | } 78 | 79 | } 80 | 81 | else 82 | { 83 | printf("输入有误!请重新登录系统!\n"); 84 | exit(1); 85 | } 86 | 87 | } 88 | 89 | return 0; 90 | } 91 | 92 | -------------------------------------------------------------------------------- /银行用户管理系统/Query_user.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: Query_user.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2016年06月27日 星期一 16时32分54秒 6 | ************************************************************************/ 7 | 8 | void my_query(Node *loop) 9 | { 10 | int number=0; 11 | 12 | loop=my_read_file(number); 13 | 14 | if(loop==NULL) 15 | { 16 | printf("银行系统里面此时没有任何账户!\n"); 17 | printf("请按下任意键返回到登陆界面!\n"); 18 | 19 | getchar(); 20 | 21 | my_register_1(); 22 | } 23 | else 24 | { 25 | char bank_number[N]; 26 | 27 | printf("请输入您要查询的用户帐号的银行卡号:\n"); 28 | 29 | scanf("%s",bank_number); 30 | 31 | while(loop!=NULL && strcmp(loop->information.Bank_number,bank_number)!=0) 32 | { 33 | loop=loop->next; 34 | } 35 | 36 | if(loop!=NULL) 37 | { 38 | printf("您查询的用户信息如下:\n"); 39 | printf("=====================================================================================================\n\n\n"); 40 | printf("姓名\t性别\t年龄\t身份证号\t银行卡号\t存钱数\t存储类别\t存储时间(月)\n\n\n"); 41 | printf("%s\t%s\t%d\t%s\t\t%s\t\t%d\t%s\t\t%d\n\n\n",loop->name,loop->sex,loop->age,loop->ID_card,\ 42 | loop->information.Bank_number,loop->information.start_money,loop->information.save_sort,\ 43 | loop->information.month); 44 | printf("=====================================================================================================\n\n\n"); 45 | 46 | printf("请按下任意键返回到登陆界面!"); 47 | 48 | while(getchar()!='\n') 49 | continue; 50 | 51 | getchar(); 52 | 53 | my_register_1(); 54 | } 55 | else 56 | { 57 | printf("您输入的银行卡号在银行系统中没有对应的账户资料!\n"); 58 | printf("请按下任意键返回到登陆界面!\n"); 59 | 60 | while(getchar()!='\n') 61 | continue; 62 | 63 | getchar(); 64 | 65 | my_register_1(); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /银行用户管理系统/Amend_password.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: Amend_password.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2016年06月27日 星期一 16时56分30秒 6 | ************************************************************************/ 7 | 8 | void my_amend_password() 9 | { 10 | FILE *fp,*f; 11 | 12 | fp=fopen("银行系统登录文件","r"); 13 | if(fp==NULL) 14 | { 15 | printf("文件打开失败!\n"); 16 | exit(1); 17 | } 18 | 19 | char old_password_1[N]; 20 | char old_password_2[N]; 21 | char new_password_1[N]; 22 | char new_password_2[N]; 23 | 24 | printf("您现在准备进行银行系统密码修改操作:\n"); 25 | printf("请按下任意键进行确认!\n"); 26 | 27 | getchar(); 28 | 29 | fscanf(fp,"%s",old_password_1); 30 | 31 | printf("请输入原密码:\n"); 32 | 33 | scanf("%s",old_password_2); 34 | 35 | if(strcmp(old_password_1,old_password_2)!=0) 36 | { 37 | printf("您输入的原密码错误,请按下任意键返回到登陆界面!\n"); 38 | 39 | while(getchar()!='\n') 40 | continue; 41 | 42 | getchar(); 43 | 44 | my_register_1(); 45 | } 46 | else 47 | { 48 | f=fopen("银行系统登录文件","wt"); 49 | 50 | if(f==NULL) 51 | { 52 | printf("文件打开失败!\n"); 53 | exit(1); 54 | } 55 | 56 | printf("您输入的原密码正确!请输入要修改的密码:\n"); 57 | 58 | scanf("%s",new_password_1); 59 | 60 | printf("请再输入一次要修改的密码:\n"); 61 | 62 | scanf("%s",new_password_2); 63 | 64 | while(strcmp(new_password_1,new_password_2)!=0) 65 | { 66 | printf("您输入的两次密码不相同,请重新开始输入一个新密码:\n"); 67 | 68 | scanf("%s",new_password_1); 69 | 70 | printf("请再输入一次要修改的密码:\n"); 71 | 72 | scanf("%s",new_password_2); 73 | } 74 | 75 | if(strcmp(new_password_1,new_password_2)==0) 76 | { 77 | fprintf(f,"%s",new_password_1); 78 | 79 | printf("您的密码修改成功,请按下任意键返回到登陆界面!\n"); 80 | 81 | while(getchar()!='\n') 82 | continue; 83 | 84 | getchar(); 85 | 86 | my_register_1(); 87 | } 88 | } 89 | 90 | fclose(fp); 91 | } 92 | -------------------------------------------------------------------------------- /银行用户管理系统/Register.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: 银行用户信息操作管理系统(登录界面).c 3 | > Author: 4 | > Mail: 5 | > Created Time: 2016年06月23日 星期四 17时01分13秒 6 | ************************************************************************/ 7 | 8 | void my_register_1() 9 | { 10 | printf(" ************************************************\n\n\n"); 11 | printf(" 欢迎登录银行用户信息操作管理系统\n\n\n"); 12 | printf(" ************************************************\n\n\n"); 13 | printf("**********************************************************************************************************\n\n\n"); 14 | printf(" 登录界面\n\n\n"); 15 | printf(" 1)查看银行所拥有的账户(文件名) 2)创建账户信息(添加新文件)\n\n\n"); 16 | printf(" 3)用户交易操作(添加新用户) 4)修改用户信息\n\n\n"); 17 | printf(" 5)用户信息删除 6) 查询用户信息\n\n\n"); 18 | printf(" 7)保存账户到磁盘文件中 8)修改系统密码\n\n\n"); 19 | printf(" 退出系统\n\n\n"); 20 | printf(" 注意:新创建账户信息的文件名如果和系统中的一个文件名相同的话则覆盖原有文件数据!\n\n"); 21 | printf(" 选项之外任意按键会退出系统!\n"); 22 | printf("**********************************************************************************************************\n\n\n"); 23 | printf("请输入要操作的选项:\n"); 24 | } 25 | 26 | void my_register_2() 27 | { 28 | printf("**********************************************************************************************************\n\n\n"); 29 | printf(" 1)添加用户(默认位置) 2)添加用户(指定位置) 3)添加用户(起始位置)\n\n\n"); 30 | printf("**********************************************************************************************************\n\n\n"); 31 | printf("请输入要操作的选项:\n"); 32 | } 33 | 34 | void my_register_3() 35 | { 36 | printf("**********************************************************************************************************\n\n\n"); 37 | printf(" 1)存钱 2)取钱\n\n\n"); 38 | printf("**********************************************************************************************************\n\n\n"); 39 | printf("请输入要操作的选项:\n"); 40 | } 41 | -------------------------------------------------------------------------------- /银行用户管理系统/Add_user.h: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: Options.h 3 | > Author: 4 | > Mail: 5 | > Created Time: 2016年06月23日 星期四 16时07分30秒 6 | ************************************************************************/ 7 | 8 | Node *add_user(Node *temp,int amount); 9 | 10 | Node *my_trade(int large) 11 | { 12 | int number;//要进行的选项 13 | int people;//要添加的账户人数 14 | int Out_money;//取钱数 15 | char Bank_figure[N];//输入的银行卡号 16 | Node *tmp,*loop=NULL; 17 | FILE *fp; 18 | char fp_name[N]; 19 | 20 | printf("请输入要添加进的文件名:\n"); 21 | scanf("%s",fp_name); 22 | 23 | fp=fopen(fp_name,"r"); 24 | 25 | if(fp==NULL) 26 | { 27 | printf("系统中没有账户文件!请先新建账户文件!\n"); 28 | printf("请按下任意键返回到登陆界面!\n"); 29 | 30 | while(getchar()!='\n') 31 | continue; 32 | 33 | getchar(); 34 | 35 | my_register_1(); 36 | } 37 | else 38 | { 39 | int number=1; 40 | 41 | loop=my_read_file(large); 42 | 43 | if(loop==NULL) 44 | { 45 | printf("银行里没有任何用户信息!\n"); 46 | printf("请添加银行用户信息!\n"); 47 | printf("请按下任意键进行下一步!\n"); 48 | 49 | while(getchar()!='\n') 50 | continue; 51 | 52 | getchar(); 53 | } 54 | 55 | my_register_3(); 56 | 57 | scanf("%d",&number); 58 | 59 | if(number==1) 60 | { 61 | printf("请输入要添加用户的个数:\n"); 62 | 63 | scanf("%d",&people); 64 | 65 | while(people<=0) 66 | { 67 | printf("请输入的用户数大于0!请再输入一次!\n"); 68 | scanf("%d",&people); 69 | } 70 | 71 | if(people>0) 72 | { 73 | tmp=add_user(loop,people); 74 | } 75 | 76 | return tmp; 77 | } 78 | 79 | if(number==2) 80 | { 81 | tmp=loop; 82 | 83 | if(loop==NULL) 84 | { 85 | printf("此时银行账户文件中没有任何用户!\n"); 86 | printf("请按下任意键返回到登陆界面,先添加新用户!\n"); 87 | 88 | while(getchar()!='\n') 89 | continue; 90 | 91 | getchar(); 92 | 93 | my_register_1(); 94 | } 95 | else 96 | { 97 | printf("请输入您的银行卡号:\n"); 98 | scanf("%s",Bank_figure); 99 | 100 | if(loop!=NULL) 101 | { 102 | while(loop!=NULL&&strcmp(loop->information.Bank_number,Bank_figure)!=0) 103 | { 104 | loop=loop->next; 105 | } 106 | 107 | if(loop==NULL) 108 | { 109 | printf("您输入的银行帐户资料查找不到!\n"); 110 | printf("请按下任意键返回到登陆界面!\n"); 111 | 112 | while(getchar()!='\n') 113 | continue; 114 | 115 | getchar(); 116 | 117 | my_register_1(); 118 | } 119 | else 120 | { 121 | printf("请输入您要取的钱数:\n"); 122 | 123 | while(scanf("%d",&Out_money)!=1) 124 | { 125 | printf("您输入的数字有误!\n请重新输入!\n"); 126 | scanf("%d",&Out_money); 127 | } 128 | 129 | loop->information.start_money=loop->information.start_money-Out_money; 130 | 131 | printf("您已经成功取出%d元,您的账户中还剩下%d元!\n",Out_money,loop->information.start_money); 132 | 133 | printf("请按下任意键返回到登陆界面!\n"); 134 | 135 | while(getchar()!='\n') 136 | continue; 137 | 138 | getchar(); 139 | 140 | my_register_1(); 141 | 142 | return tmp; 143 | } 144 | } 145 | } 146 | } 147 | } 148 | } 149 | 150 | Node *add_user(Node *temp,int amount) 151 | { 152 | int figure; 153 | char bank_number[N]; 154 | 155 | my_register_2(); 156 | 157 | scanf("%d",&figure); 158 | 159 | Node *p,*q,*phead=NULL; 160 | int i; 161 | 162 | p=(Node *)malloc(sizeof(Node)); 163 | if(p==NULL) 164 | exit(1); 165 | 166 | printf("请输入要添加用户的姓名,性别,年龄,身份证号,银行卡号,要存的钱数,存储类型,存储时间(月):\n"); 167 | scanf("%s%s%d%s%s%d%s%d",p->name,p->sex,&p->age,p->ID_card,p->information.Bank_number,&p->information.start_money\ 168 | ,p->information.save_sort,&p->information.month); 169 | 170 | phead=p; 171 | 172 | for(i=0;iname,q->sex,&q->age,q->ID_card,q->information.Bank_number,&q->information.start_money\ 179 | ,q->information.save_sort,&q->information.month); 180 | 181 | q->next=NULL; 182 | p->next=q; 183 | p=q; 184 | } 185 | 186 | Node *pre,*Phead; 187 | 188 | if(figure==1) 189 | { 190 | pre=temp; 191 | Phead=pre; 192 | 193 | while(temp!=NULL) 194 | { 195 | pre=temp; 196 | temp=temp->next; 197 | } 198 | 199 | pre->next=phead; 200 | } 201 | 202 | if(figure==2) 203 | { 204 | Phead=temp; 205 | 206 | printf("您将要把这些用户添加到您指定的位置后面!\n"); 207 | printf("请输入您要指定的位置(指定位置上前一个用户的银行卡号):\n"); 208 | 209 | scanf("%s",bank_number); 210 | 211 | while(strcmp(bank_number,temp->information.Bank_number)!=0) 212 | { 213 | temp=temp->next; 214 | } 215 | 216 | p->next=temp->next; 217 | temp->next=phead; 218 | } 219 | 220 | if(figure==3) 221 | { 222 | p->next=temp; 223 | Phead=phead; 224 | } 225 | 226 | printf("您成功的添加了%d个用户的资料!\n\n",amount); 227 | printf("请按下任意键返回到登陆界面!\n"); 228 | 229 | while(getchar()!='\n') 230 | continue; 231 | 232 | getchar(); 233 | 234 | my_register_1(); 235 | 236 | return Phead; 237 | } 238 | -------------------------------------------------------------------------------- /哈弗曼编码译码器/哈弗曼编码译码器.c: -------------------------------------------------------------------------------- 1 | /************************************************************************* 2 | > File Name: 哈弗曼编码译码器.c 3 | > Author: Paranoid 4 | > Mail: championhengyi@gmail.com 5 | > Created Time: 2016年12月25日 星期日 17时19分56秒 6 | ************************************************************************/ 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | #define N 256 17 | #define LEAVECODE 256 18 | #define CODE 2* LEAVECODE -1 19 | #define MAX 30000 20 | #define DEPTH LEAVECODE -1 21 | 22 | typedef struct{ //哈弗曼树结点的数据结构 23 | int weight; 24 | int parent, lchild, rchild; 25 | }HUFFMAN_CODE; 26 | 27 | char file_name[N]; //源文件名是全局变量 28 | unsigned long int od_file_size; //临时二进制文件的大小 29 | HUFFMAN_CODE huffman_code[CODE]; //哈弗曼树 30 | 31 | int interface(); 32 | void code(); 33 | void decode(); 34 | void R_file(unsigned char string[]); 35 | void Huffman_tree(unsigned char leave_code[]); 36 | void sele_ct(int *s1, int *s2); 37 | void Create_Code(char *str_code[]); 38 | void Tmp_file(char *str_code[]); 39 | void Cut_file(); 40 | void revert(); 41 | void Source_file(); 42 | 43 | int interface() //界面 44 | { 45 | int number; 46 | 47 | printf("1.编码\n"); 48 | printf("2.译码\n"); 49 | 50 | printf("请输入您的选项:\n"); 51 | scanf("%d", &number); 52 | 53 | return number; 54 | } 55 | 56 | void code() //编码 57 | { 58 | int i; 59 | unsigned char leave_code[LEAVECODE]; 60 | char *str_code[LEAVECODE]; 61 | HUFFMAN_CODE huffman_code[CODE]; 62 | 63 | for(i = 0; i < LEAVECODE; i++) //初始化叶子节点权值 64 | { 65 | leave_code[i] = 0; 66 | } 67 | 68 | for(i = 0; i < LEAVECODE; i++) //初始化叶子节点编码 69 | { 70 | str_code[i] = NULL; 71 | } 72 | 73 | R_file(leave_code); //读文件,将字符权值记录下来 74 | 75 | Huffman_tree(leave_code); //拥有字符权值,构建哈弗曼树 76 | 77 | Create_Code(str_code); //构造每个字符编码 78 | 79 | Tmp_file(str_code); //创建临时文件,将编码写入文件之中 80 | 81 | Cut_file(); //压缩文件 82 | } 83 | 84 | void R_file(unsigned char leave_code[]) //读文件,将字符权值记录下来 85 | { 86 | int fd; 87 | int ret; 88 | unsigned char tmp_str; 89 | 90 | printf("请输入您要进行编码的文件名:\n"); 91 | scanf("%s", file_name); 92 | 93 | if((fd = open(file_name, O_RDONLY)) == -1) 94 | { 95 | printf("进行编码的文件打开失败\n"); 96 | exit(1); 97 | } 98 | 99 | while((ret = read(fd, &tmp_str, 1)) > 0) //每次从文件中读一个字节,直到文件读完为止 100 | { 101 | leave_code[tmp_str]++; //记录文件中字符的权值 102 | } 103 | } 104 | 105 | void Huffman_tree(unsigned char leave_code[]) //构建哈弗曼树 106 | { 107 | int i; 108 | int s1, s2; 109 | 110 | for(i = 0; i < LEAVECODE; i++) //初始化叶子节点 111 | { 112 | huffman_code[i].weight = leave_code[i]; 113 | huffman_code[i].parent = 0; 114 | huffman_code[i].lchild = 0; 115 | huffman_code[i].rchild = 0; 116 | } 117 | 118 | for(i = LEAVECODE; i < CODE; i++) //初始化构造节点 119 | { 120 | huffman_code[i].weight = 0; 121 | huffman_code[i].parent = 0; 122 | huffman_code[i].lchild = 0; 123 | huffman_code[i].rchild = 0; 124 | } 125 | 126 | for(i = LEAVECODE; i < CODE; i++) //构建新结点 127 | { 128 | s1 = -1; s2 = -1; 129 | sele_ct(&s1, &s2); //在叶子结点中找到最小值和次小值 130 | if(s2 == -1 || s1 == -1) //若次小值没被找到,则哈弗曼树建立完成 131 | { 132 | break; 133 | } 134 | 135 | huffman_code[i].weight = huffman_code[s1].weight + huffman_code[s2].weight; 136 | huffman_code[i].lchild = s1; 137 | huffman_code[i].rchild = s2; 138 | huffman_code[s1].parent = i; 139 | huffman_code[s2].parent = i; 140 | } 141 | } 142 | 143 | void sele_ct(int *s1, int *s2) //在叶子结点中找到最小值和次小值 144 | { 145 | int i; 146 | int min = MAX, minor = MAX; 147 | 148 | for(i = 0; i < CODE; i++) //最小值 149 | { 150 | if(huffman_code[i].weight != 0 && huffman_code[i].parent == 0) 151 | { 152 | if(min > huffman_code[i].weight) 153 | { 154 | min = huffman_code[i].weight; 155 | *s1 = i; 156 | } 157 | } 158 | } 159 | 160 | for(i = 0; i < CODE; i++) //次小值 161 | { 162 | if(huffman_code[i].weight != 0 && huffman_code[i].parent == 0 && i != *s1) 163 | { 164 | if(minor > huffman_code[i].weight) 165 | { 166 | minor = huffman_code[i].weight; 167 | *s2 = i; 168 | } 169 | } 170 | } 171 | 172 | printf("%d, %d\n", *s1, *s2); //打印每次找到的最小值和次小值的位置 173 | } 174 | 175 | void Create_Code(char *str_code[]) //构造每个字符的编码 176 | { 177 | char *cd; 178 | int start; 179 | int i, c, p; 180 | 181 | cd = (char *)malloc(LEAVECODE * sizeof(char)); 182 | cd[LEAVECODE -1] = '\0'; 183 | 184 | for(i = 0; i < LEAVECODE; i++) 185 | { 186 | if(huffman_code[i].weight == 0) 187 | continue; 188 | 189 | start = LEAVECODE -1; 190 | c = i; //当前结点 191 | p = huffman_code[i].parent; //双亲结点 192 | 193 | while(p != 0) //双亲结点不为0 194 | { 195 | --start; 196 | 197 | if(huffman_code[p].lchild == c) 198 | cd[start] = '0'; 199 | 200 | if(huffman_code[p].rchild == c) 201 | cd[start] = '1'; 202 | 203 | c = p; 204 | p = huffman_code[p].parent; 205 | } 206 | 207 | str_code[i] = (char *)malloc((LEAVECODE -start)*sizeof(char)); //申请编码空间 208 | strcpy(str_code[i], &cd[start]); 209 | } 210 | 211 | free(cd); 212 | } 213 | 214 | void Tmp_file(char *str_code[]) //创建临时文件,将编码写入文件之中 215 | { 216 | int fd1, fd2; 217 | int ret; 218 | unsigned char tmp_str; 219 | struct stat buf; 220 | 221 | if((fd1 = open("tmp", O_RDWR | O_CREAT | O_TRUNC, S_IRWXU)) == -1) 222 | { 223 | printf("建立临时文件失败\n"); 224 | exit(1); 225 | } 226 | 227 | if((fd2 = open(file_name, O_RDONLY)) == -1) 228 | { 229 | printf("打开源文件失败\n"); 230 | exit(1); 231 | } 232 | 233 | for(int i = 0; i < LEAVECODE; i++) //打印每个字符的编码 234 | { 235 | printf("str_code[%d]: %s\n", i, str_code[i]); 236 | } 237 | 238 | while((ret = read(fd2, &tmp_str, 1)) == 1) //每次从文件中读一个字节,直到文件读完为止 239 | { 240 | //if(str_code[tmp_str] == NULL) 241 | // continue; 242 | 243 | if(write(fd1, str_code[tmp_str], strlen(str_code[tmp_str])) == -1) 244 | { 245 | printf("编码写入临时文件失败\n"); 246 | exit(1); 247 | } 248 | } 249 | 250 | if(fstat(fd1, &buf) == -1) 251 | { 252 | printf("获取编码临时文件属性失败\n"); 253 | exit(1); 254 | } 255 | 256 | od_file_size = (unsigned long int) buf.st_size; //最初的二进制文件大小 257 | printf("od_file_size: %ld\n", od_file_size); 258 | 259 | if(buf.st_size % 8 != 0) //补齐临时文件字节 260 | { 261 | for(int i = 0; i < buf.st_size % 8; i++) 262 | { 263 | tmp_str = '0'; 264 | if(write(fd1, &tmp_str, 1) == -1) 265 | { 266 | printf("补齐临时文件失败\n"); 267 | exit(1); 268 | } 269 | } 270 | } 271 | } 272 | 273 | void Cut_file() //压缩文件 274 | { 275 | int fd1, fd2; 276 | int count; 277 | unsigned char str = 0; //将八位二进制转换为一个无符号字节 278 | unsigned char tmp_str; 279 | char cut_file_name[N]; 280 | struct stat buf; 281 | 282 | printf("请输入压缩文件名:\n"); 283 | scanf("%s", cut_file_name); 284 | 285 | if((fd1 = open("tmp", O_RDONLY)) == -1) 286 | { 287 | printf("打开临时文件失败\n"); 288 | exit(1); 289 | } 290 | 291 | if(fstat(fd1, &buf) == -1) 292 | { 293 | printf("获取临时文件属性失败\n"); 294 | exit(1); 295 | } 296 | 297 | printf("buf.st_size: %d\n", buf.st_size); //补齐字节后的文件大小 298 | count = buf.st_size / 8; //记录八位二进制转换为一个无符号字节的次数 299 | 300 | if(lseek(fd1, SEEK_SET, 0) == -1) 301 | { 302 | printf("文件指针移动失败\n"); 303 | exit(1); 304 | } 305 | 306 | if((fd2 = open(cut_file_name, O_CREAT | O_APPEND | O_RDWR, S_IRWXU)) != -1) //创建压缩文件,向压缩文件中先记录最初二进制文件大小 307 | { 308 | if(write(fd2, &od_file_size, sizeof(unsigned long int)) != sizeof(unsigned long int)) 309 | { 310 | printf("向压缩文件中写入文件大小失败\n"); 311 | exit(1); 312 | } 313 | } 314 | 315 | for(int i = 0; i < CODE; i++) //向压缩文件中写入哈弗曼树 316 | { 317 | if(write(fd2, &huffman_code[i], sizeof(HUFFMAN_CODE)) != sizeof(HUFFMAN_CODE)) 318 | { 319 | printf("向文件中写入哈弗曼树失败\n"); 320 | exit(1); 321 | } 322 | } 323 | 324 | for(int j = 0; j < count; j++) 325 | { 326 | str = 0; 327 | for(int i = 0; i < 8; i++) //将8位二进制码转换为一位无符号字节数 328 | { 329 | if(read(fd1, &tmp_str, 1) == 1) 330 | { 331 | str = str *2 + (tmp_str -48); 332 | } 333 | } 334 | 335 | printf("str: %d\n", str); //八个二进制转换为一个字节所表示的大小 336 | 337 | if(write(fd2, &str, 1) != 1) 338 | { 339 | printf("向压缩文件中写入数据失败\n"); 340 | exit(1); 341 | } 342 | } 343 | 344 | if(remove("tmp") == -1) 345 | { 346 | printf("删除临时文件失败\n"); 347 | exit(1); 348 | } 349 | } 350 | 351 | void decode() //解压文件 352 | { 353 | revert(); //还原文件成二进制文件 354 | 355 | Source_file(); //由二进制文件得到原文件 356 | } 357 | 358 | void revert() //还原文件成二进制文件 359 | { 360 | int fd1, fd2; 361 | int i; 362 | unsigned char tmp; 363 | unsigned char str; 364 | unsigned char string[8]; 365 | 366 | printf("请输入要解压缩的文件名:\n"); 367 | scanf("%s", file_name); 368 | 369 | if((fd1 = open(file_name, O_RDONLY)) == -1) 370 | { 371 | printf("打开解压缩文件失败\n"); 372 | exit(1); 373 | } 374 | 375 | if(read(fd1, &od_file_size, sizeof(unsigned long int)) != sizeof(unsigned long int)) 376 | { 377 | printf("提取原二进制文件大小失败\n"); 378 | exit(1); 379 | } 380 | 381 | for(i = 0; i < CODE; i++) 382 | { 383 | if(read(fd1, &huffman_code[i], sizeof(HUFFMAN_CODE)) != sizeof(HUFFMAN_CODE)) 384 | { 385 | printf("提取原二进制文件所属哈弗曼树失败\n"); 386 | exit(1); 387 | } 388 | } 389 | 390 | if((fd2 = open("tmp", O_CREAT | O_APPEND | O_RDWR, S_IRUSR | S_IWUSR)) == -1) 391 | { 392 | printf("建立解压缩临时文件失败\n"); 393 | exit(1); 394 | } 395 | 396 | while(read(fd1, &str, sizeof(unsigned char)) == 1) 397 | { 398 | for(i = 7; i >= 0; i--) 399 | { 400 | tmp = str % 2; //得到二进制字符 401 | string[i] = tmp +48; 402 | str = str / 2; 403 | } 404 | 405 | if(write(fd2, string, 8) != 8) //将二进制字符写入压缩临时文件之中 406 | { 407 | printf("二进制字符写入压缩临时文件失败\n"); 408 | exit(1); 409 | } 410 | } 411 | } 412 | 413 | void Source_file() //由二进制文件得到原文件 414 | { 415 | int fd1, fd2; 416 | int foot, current; 417 | char source_file_name[N]; 418 | unsigned char tmp_str; 419 | unsigned char str; 420 | int i; 421 | HUFFMAN_CODE root; 422 | 423 | printf("请输入解压后的文件名:\n"); 424 | scanf("%s", source_file_name); 425 | 426 | if((fd1 = open("tmp", O_RDONLY)) == -1) 427 | { 428 | printf("打开解压缩临时二进制文件失败\n"); 429 | exit(1); 430 | } 431 | 432 | if((fd2 = open(source_file_name, O_CREAT | O_APPEND | O_RDWR, S_IRUSR | S_IWUSR)) == -1) 433 | { 434 | printf("建立源文件失败\n"); 435 | exit(1); 436 | } 437 | 438 | for(i = 0; i < CODE; i++) //找到根节点 439 | { 440 | if(huffman_code[i].weight != 0 && huffman_code[i].parent == 0) 441 | { 442 | root = huffman_code[i]; 443 | foot = i; 444 | current = foot; 445 | break; 446 | } 447 | } 448 | 449 | for(i = 0; i < CODE; i++) //打印哈弗曼树 450 | { 451 | printf("%d: weight:%d parent:%d lchild:%d rchild:%d ", i, huffman_code[i].weight, huffman_code[i].parent, 452 | huffman_code[i].lchild, huffman_code[i].rchild); 453 | printf("\n"); 454 | } 455 | 456 | for(i = 0; i < od_file_size; i++) 457 | { 458 | if(read(fd1, &tmp_str, 1) == 1) 459 | { 460 | if(tmp_str == '0') 461 | { 462 | current = root.lchild; 463 | root = huffman_code[root.lchild]; 464 | } 465 | if(tmp_str == '1') 466 | { 467 | current = root.rchild; 468 | root = huffman_code[root.rchild]; 469 | } 470 | 471 | if(root.lchild == 0 && root.rchild == 0) 472 | { 473 | str = (unsigned char) current; 474 | printf("str: %c\n", str); //得到源文件的源字符 475 | 476 | if(write(fd2, &str, 1) != 1) 477 | { 478 | printf("向源文件中写入字符失败\n"); 479 | exit(1); 480 | } 481 | 482 | root = huffman_code[foot]; 483 | } 484 | } 485 | } 486 | 487 | if(remove("tmp") == -1) 488 | { 489 | printf("删除解压缩临时文件失败\n"); 490 | exit(1); 491 | } 492 | } 493 | 494 | int main() 495 | { 496 | int number; 497 | 498 | number = interface(); //界面 499 | 500 | switch(number) 501 | { 502 | case 1: 503 | code(); //编码 504 | break; 505 | 506 | case 2: 507 | decode(); //译码 508 | break; 509 | } 510 | } 511 | --------------------------------------------------------------------------------