Home > Back-end >  For bosses to see see!
For bosses to see see!

Time:10-16

How to modify modify the user information and modify the function of the user's password!
# include & lt; stdio.h>
# include & lt; Stdlib. H>
# include & lt; String. H>
# define USERNAME_LEN 32
//user information structure
Typedef struct user {
Char * username;//user name
Char * password;//the user password
Char * name;//user name
//other information...
Struct user * next;//the next node
} the User;
/* *
* print user information
* @ param head head node
*/
Void show_user (User * head) {
User * temp=head;
If (temp==NULL) {
Printf (" no user information, please register first \ n ");
return;
}
Printf (" name \ \ t t username password \ n ");
While (temp) {
Printf (" % s \ n \ \ t t % s % s ", temp - & gt; The name, temp - & gt; The username, temp - & gt; Password);
Temp=temp - & gt; next;
}
}

/* *
* destroy user information
* @ param head head node
*/
Void release (User * head) {
User * temp=head;
If (temp==NULL) {
return;
}
User * next=temp - & gt; next;
While (temp) {
Has destroyed the printf (" % s \ n ", temp - & gt; The username);
Free (temp - & gt; Name);
Free (temp - & gt; The username);
Free (temp - & gt; Password);
Free (temp);
Temp=next;
If (temp!=NULL) {
Next=temp - & gt; next;
}

}
}

/* *
* save user information
* @ param head head node
* @ param user saved user information
*/
User * insert (User * head, User * User) {

If (head==NULL) {
return user;
}
The head - & gt; Next=user;
Return the head;
}
/* *
* according to the user name lookup
* @ param head head node
* @ param username username
*/
User * query1 (User * head, const char * username) {
User * temp=head;

int r=0;
While (temp) {
R=STRCMP (temp & gt; Username the username);
If (r==0) {
Return temp.
}
Temp=temp - & gt; next;
}
return NULL;

}
/* *
* according to the user name and password
* @ param head head node
* @ param username username
* @ param "password," password
*/
User * query2 (User * head, const char * username, const char * password) {
User * temp=head;
int r=0;
While (temp) {
R=STRCMP (temp & gt; Username the username);
If (r==0) {
R=STRCMP (temp & gt; The password, the password);
If (r==0) {
Return temp.
}
return NULL;

}
Temp=temp - & gt; next;
}
return NULL;
}



/* *
* registration
* @ param head head node (not NULL)
* @ return head node
*/
User * sign (User * head) {
Char * username=NULL;
Char * password=NULL;
Char * name=NULL;
Printf (" please enter your user name (English and Numbers, the longest % d) : \ n ", USERNAME_LEN);
The username=(char *) calloc (USERNAME_LEN, sizeof (char));

The scanf (" % s ", username);

User * User=query1 (head, username);
Int flag=(user!=NULL);
While (flag) {
Printf (" the user name already exists, please re-entry: \ n ");
The scanf (" % s ", username);
Flag=(STRCMP (user - & gt; Username the username)==0);
}
Username: printf (" % s \ n ", username);

Printf (" please enter the password (% d) longest: \ n ", USERNAME_LEN);
Password=(char *) calloc (USERNAME_LEN, sizeof (char));
The scanf (" % s ", ");
Printf (" password: % s \ n ", ");

Printf (" please enter your name (% d) longest: \ n ", USERNAME_LEN);
Name=(char *) calloc (USERNAME_LEN, sizeof (char));
The scanf (" % s ", name);
Name: printf (" % s \ n ", name);

User * new_user=(User *) calloc (1, sizeof (User));
New_user - & gt; The username=username;
New_user - & gt; Password=password;
New_user - & gt; Name=name;
New_user - & gt; Next=NULL;
The head=insert (head, new_user);
Printf (" registration completed \ n ");
Return the head;

}

/* *
* login
* @ param head head node
* @ return after the success of the login user information login failure returns NULL
*/
The login User * (User * head) {
Char * username=NULL;
Char * password=NULL;
Int flag=1;
User * current_user=NULL;
While (current_user==NULL)
{

Printf (" please enter the user name: \ n ");
The username=(char *) calloc (USERNAME_LEN, sizeof (char));
The scanf (" % s ", username);
Printf (" please enter the password: \ n ");
Password=(char *) calloc (USERNAME_LEN, sizeof (char));
The scanf (" % s ", ");

Current_user=query2 (head, username, password);
If (current_user==NULL) {
Printf (" the user name or password mistake, enter 1 to continue to login, enter 0 to cancel login: ");
The scanf (" % d ", & amp; The flag);
If (flag==0) {
return NULL;
}
}

}

Printf (" login is successful, you are welcome: % s \ n ", current_user - & gt; Name);
Return the current_user;
}



Int main (int arg c, char * argv []) {
User * head=NULL;
Int num=1;
printf("\n");
Printf (" * * * * * * * * * * * * * * * welcome to * * * * * * * * * * * * * * * \ n ");
Printf (" 0: exit system \ t1: register new users \ n ");
printf("\n");
Printf (" 2: display all users \ t3: remove all user \ n ");
Printf (" 4: login \ t \ n ");
printf("\n");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
printf("\n");

While (num)
{
Printf (" input number, perform actions: ");
The scanf (" % d ", & amp; Num);
The switch (num)
{
Case 0:
Release (the head);
Printf (" goodbye, welcome next time landing \ n ");
break;
Case 1:
The head=sign (the head);
break;
Case 2:
Show_user (head);
break;
Case 3:
Release (the head);
The head=NULL; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related