Created
June 7, 2015 08:22
-
-
Save lcy101u/e518f7f432c6af1e9bd5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#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"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
struct node | |
{ | |
char name[10]; | |
char password[10]; | |
struct node *next; | |
}; | |
typedef struct node node; | |
node * readtext(FILE *p); | |
node * add_to_list(node *first); | |
node * add_to_tail(node *first); | |
int search_name(node *,char *,char *); | |
int login(node *first); | |
void print_admin_list(); | |
void print_staff_list(); | |
void add_staff(node *); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <string.h> | |
#include <stdio.h> | |
#include "kk.h" | |
int main() | |
{ | |
int i; | |
char c; | |
FILE *p; | |
node *first; | |
p=fopen("staff.txt","r"); | |
first=readtext(p); | |
i=login(first); | |
if(i==0) | |
{ | |
print_admin_list(); | |
scanf(" %c",&c); | |
//---------option-----------// | |
if(c=='A')add_staff(first); | |
} | |
else | |
{ | |
print_staff_list(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment