一.注册算法
void addNewUser(){ int exist; char name[10]; char psw[10]; User *head,*p; Content *con; if(user_num==10){ printf("Has 10 users!\n"); return; } do{ printf("Input New User Name(0~10):\n"); scanf("%s",name); exist=0; head=user->next; while(head!=NULL){ if(strcmp(head->name,name)==0){ exist=1; break; } head=head->next; } if(exist==1) printf("The User Have Existed!\nPlease Input Again:"); }while(exist==1); printf("Input New User Password(0~10):\n"); scanf("%s",psw); p=(User *)malloc(sizeof(User)); strcpy(p->name,name); strcpy(p->psw,psw); con=(Content *)malloc(sizeof(Content)); con->next=NULL; p->con=con; p->next=NULL; head=user; while(head->next!=NULL) head=head->next; head->next=p; user_num++; printf("Add New User Success!\n"); }
二.登录算法
void login(){ int choice; int find=0; int login=0; char name[10]; char psw[10]; User *head=user->next;; //clrscr(); do{ printf("Input Your UaerName:"); scanf("%s",name); while(head!=NULL){ if(strcmp(name,head->name)==0){ find=1; break; } head=head->next; } if(find==0) printf("The Username Not Exist!\n"); }while(find==0); do{ printf("Input Your Password:"); scanf("%s",psw); if(strcmp(psw,head->psw)==0) login=1; if(login==0) printf("The Psw Is Wrong!\nPlease Input Again:"); }while(login==0); printf("Login Success!\n"); do{ printf("\n********Hello %s!*******\n",head->name); printf("1. Display All Contents\n"); printf("2. New A Content\n"); printf("3. Delete Content\n"); printf("4. Into Content\n"); printf("0. Return Main Menu\n"); printf("************************\n\n"); printf("Input Your Choice:"); scanf("%d",&choice); switch(choice){ case 1:display_contents(head);break; case 2:add_content(head);break; case 3:del_content(head);break; case 4:into_content(head);break; } }while(choice!=0); }
三.实现思路
注册算法addNewUser():
登录算法 login()