#include #include #include #include "kk.h" node * readtext(FILE *p) { char buf[300]; char *ptr; int i=0; node * last=NULL; node * first=NULL; while(fgets(buf,300,p)!=NULL) { if(i==0) { first=add_to_list(first); last=first; i++; } else { last=add_to_tail(last); } ptr=buf; buf[strlen(buf)-2]='\0'; ptr=strtok(buf,"\t"); while(ptr!=NULL) { if(strncmp(ptr,"Name",4)==0) { ptr=ptr+5; strcpy(last->name,ptr); } else if(strncmp(ptr,"password",8)==0) { ptr=ptr+9; strcpy(last->password,ptr); } ptr=strtok(NULL,"\t"); } } return first; } node * add_to_list(node *first) { node *new_node; new_node=malloc(sizeof(node)); if(new_node==NULL) { printf("error:malloc failed in create_list\n"); exit(EXIT_FAILURE); } new_node->next=first; return new_node; } node * add_to_tail(node *last) { node *new_node; new_node=malloc(sizeof(node)); if(new_node==NULL) { printf("error:malloc failed in add_to_list\n"); exit(EXIT_FAILURE); } last->next=new_node; new_node->next = NULL; return new_node; } int search_name(node *list,char *name,char *password) { int found=0; char *ptr=password; while(list != NULL) { if(strcmp(list->name,name) == 0) { printf("password:"); scanf("%s",password); if(strcmp(list->password,ptr) == 0) { found=1; break; } } list=list->next; } return found; } int login(node *first) { int i; char staff_name[20]; char staff_password[20]; while(1) { printf("name:"); scanf(" %s",staff_name); i=search_name(first,staff_name,staff_password); if(i==0) { printf("can't found\n"); continue; } if(strcmp(staff_name,"admin")==0) { printf("------admin mode------\n"); return 0; } printf("------staff mode------\n"); return 1; } } void print_admin_list() { printf("A)Add staff\nB)Delete staff\nC)Edit staffname/password\nD)view stafflist (in orders)\E)output staff info to the file\nE)output staff info to the file\n"); } void print_staff_list() { printf("F)Load customer account\nG)Create new customer account\nH)Cash deposit\nI)Cash withdrawl\nJ)Fund transfer\nK)Account info\nL)Transaction info\nM)Log out\n"); } void add_staff(node *first) { char password[20]; char name[20]; while(1) { int i; printf("name:"); scanf("%s",name); i=search_name(first,name,password); if(i==1) { printf("the staff has already exist\n"); continue; } break; } printf("password:"); scanf("%s",password); node *last; last=first; while(last->next!=NULL) { last=last->next; } last=add_to_tail(last); strcpy(last->name,name); strcpy(last->password,password); printf("%s\n",last->name); printf("%s\n",last->password); printf("success\n"); } }