“This is the 14th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”
The profile
In the introduction of the last demonstration of the library management system results, this one mainly explains the code and ideas
Define structs and global variables
In the structure array, the definition of the book is mainly divided into isbn, title, publisher, time, borrowing status, except the title and publisher are string array, the other are int type
Struct book {int num; Char name[20]; // char publish[20]; Struct time {int year,month,day; }t; int lend; }bk[20]; int N; Char code[20] = "mm"; / / passwordCopy the code
The main menu
I don’t have much to say about that, but I’m going to use int to store the user’s choices and return the result, okay
Int mainmenu() // mainmenu {int x; printf("\n\n\n\n"); printf("\t\t|-------------------------------------------------------------|\n"); printf("\t\t| |\n"); printf("\t\t| ====================== |\n"); Printf (" \ t \ t | | welcome to the books management system \ n "); printf("\t\t| ====================== |\n"); printf("\t\t| |\n"); Printf (" \ t \ t | 1. Administrator mode | \ n "); Printf (" \ t \ t | 2. Client mode | \ n "); Printf (" \ t \ t | 3. Quit system | \ n "); printf("\t\t|--------------------------------------------------------------|\n"); Printf ("\n\t\t please enter your choice :"); scanf("%d",&x); return x; }Copy the code
Password verification and password change
Password authentication is mainly used by comparing the input password with the stored password. If the password is the same, 1 is returned; if the password is different, 0 is returned. Here is a brief introduction to STRCMP function, which compares two strings. If str1<str2, return a negative number; If str1>str2, a positive number is returned.
Int codeverify() {char mm[20]; Printf ("\n"); printf("\t\t ====================== \n"); Printf ("\t\t welcome administrator mode \n"); printf("\t\t ====================== \n"); printf("\n"); Printf ("\t\t please enter password :"); scanf("%s",&mm); if(! STRCMP (mm,code)) // Compares whether the entered password is the same as the original password {return 1; } else { return 0; }}Copy the code
Change passwords that mainly use the three character array respectively storing user password, enter a new password for the first time, the second input the new password, first to compare the input password to the original password is the same, can only modify the password is the same situation, different tip password mistake is not allowed to change directly, If the passwords are the same, enter the passwords twice and compare them. If the passwords are the same, a message is displayed indicating that the passwords are changed successfully. Otherwise, the message is displayed indicating that the passwords are different.
Int changecode() // Change password {char code_temp[20]; Char new_code[20]; Char new_code1[20]; // Save the second new password printf(" please enter the original password: \n"); scanf("%s",&code_temp); if(! STRCMP (code_temp,code)) // Compare the original password with the password entered by the user {printf(" Please enter a new password: \n"); scanf("%s",&new_code); Printf (" Please type again: \n"); scanf("%s",&new_code1); if(! STRCMP (new_code1,new_code)) // Compare the password entered after two changes {strcpy(code,new_code); Printf (" Password changed successfully, please remember, press any key to return... \n"); getch(); return 0; } else {printf(" Error! If the password entered twice is inconsistent, press any key to return... \n"); getch(); return 1; }} else {printf(" Original password error, press any key to return... \n"); getch(); }}Copy the code