# include & ltstdlib.h & gt// Common functions
# include & ltstring.h & gt// string function
# include & ltconio.h & gt// Text window function
Struct record// defines the structure.
{
char name[20]; //Name
Charging phone [12]; //telephone //int
Char address [50]; //address
Char postal code [8]; //Postal code
char e _ mail[20]; //E-mail.
} students [100]; //Suppose the maximum number is 100.
//Define the global variable num, which indicates the number of people already entered.
Int num// here we use arrays to solve the address book problem. Actually, the linked list is better.
int menu_select()
{
char s[80]; //array
int a; /* Define an integer variable */
System ("CLS"); //Brush the screen
Printf ("\ t \ t * * * * * * * Welcome to the communication management interface * * * * * * * * \ n ");
Printf("\t\t\t0。 Input record \ n ");
Printf("\t\t\t 1。 Show records \ n ");
Printf("\t\t\t2。 Find by name \ n ");
Printf("\t\t\t3。 Search by phone number \ n ");
Printf("\t\t\t4。 Insert record \ n ");
Printf("\t\t\t5。 Sort by name \ n ");
Printf("\t\t\t6。 Delete record \ n ");
printf("\t\t\t7。 Exit \ n ");
printf(" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n \ n ");
Do {
Printf ("Enter your choice (0 ~ 7):");
scanf("%s ",s);
a = atoi(s); //Type conversion
}
while(a & lt; 0 | | a & gt7);
Return to a;
}
int adduser()
{
Printf ("\ t \ t * * * * * * Please enter user information * * * * * * * * * * * * * *");
Printf ("\ t \ t \ tEnter name: \ n");
Scanf("%s ",student [number]. Name);
Printf ("\ t \ t \ tEnter phone number: \ n");
Scanf("%s ",student [number]. Telephone);
Printf ("\ t \ t \ tEnter address: \ n");
Scanf("%s ",student [number]. Address);
Printf ("\ t \ t \ tEnter postal code: \ n");
Scanf("%s ",student [number]. Postal code);
Printf ("\ t \ t \ tEnter email: \ n");
Scanf("%s ",student [number]. E-mail);
num++;
Printf ("\ t \ t \ tDo you want to continue adding? (Yes/No): \ n ");
if(getch()=='y' || getch()=='Y ')
adduser();
return(0);
}
Invalid list ()
{
int I;
System ("CLS");
If (num! =0)
{
Printf ("\ t \ t \ t * * * * * * * * * following is all the information in the address book * * * * * * * \ n ");
for(I = 0; I & ltnumi++)
{
Printf ("\ t \ t \ tname: %s\n ",student[i]。 Name);
Printf ("\ t \ t \ tTel: %s\n ",student[i]。 Telephone);
Printf ("\ t \ t \ taAddress:% s \ n", student [i]. Address);
Printf ("\ t \ t \ tPostal code: %s\n ",student[i]. Postal code);
printf("\t\t\te-mail:%s\n ",student[i]。 E-mail);
if(I+ 1 & lt; Numbers)
{
System ("suspended");
}
}
printf(" \ t \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
}
other
Printf ("\ t \ t \ tThere is no record in the address book \ n");
Printf ("\ t \ t \ tPress any key to return to the main menu: \ n");
getch(); //Here is the input character without echo, and the character you entered will not be displayed on the screen.
Return;
}
int searchbyname()
{
int mark = 0;
int I;
Printf ("\ t \ t \ t * * * * * * * * Search by name * * * * * * * * * * *);
char name[20];
Printf ("\ t \ t \ tPlease enter a name: \ n");
Scanf("%s ",name);
for(I = 0; I & ltnumi++)
{
Comparison of if (strcmp (student [I]). Name, name)= = 0)// String
{
Printf(" \ t \ t \ t * * * * * * * * * is the user information you are looking for * * * * * * *);
Printf ("\ t \ t \ tname: %s ",student[i]。 Name);
Printf ("\ t \ t \ tTel: %s ",student[i]。 Telephone);
Printf ("\ t \ t Address:% s ",student [i]. Address);
printf("\t\t\te-mail:%s ",student[i]。 E-mail);
printf(" \ t \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
mark++;
if((I+ 1)& lt; Num)// Find user information with the same name.
{
Printf ("\ t \ t \ tDo you want to continue searching for user information with the same name: (y/n) \ n");
if(getch()=='y' || getch()=='Y ')
{
Continue;
}
other
return(0);
}
other
{
Printf ("\ t \ t \ tPress any key to return to the main menu");
getch();
return(0);
}
}
}
If (flag == 0)
{
Printf ("\ t \ t \ tThere is no user record with the same name \ n");
Printf ("\ t \ t \ tPress any key to return to the main menu \ n");
getch();
return(0);
}
Returns 0;
}
int searchbyphone()
{
int mark = 0;
int I;
Printf ("\ t \ t \ t * * * * * * * * * * * * * * * Search by phone * * * * * * * ");
Charging phone [10];
Printf ("\ t \ t \ tPlease enter a phone number: \ n");
Scanf("%s ",telephone);
for(I = 0; I & ltnumi++)
{
if (strcmp(student[i])。 Telephone, telephone) ==0)
{
Printf(" \ t \ t \ t * * * * * * * * * is the user information you are looking for * * * * * * *);
Printf ("\ t \ t \ tname: %s ",student[i]。 Name);
Printf ("\ t \ t \ tTel: %s ",student[i]。 Telephone);
Printf ("\ t \ t Address:% s ",student [i]. Address);
printf("\t\t\te-mail:%s ",student[i]。 E-mail);
printf(" \ t \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf ("\ t \ t \ tPress any key to return to the main menu \ n");
mark++;
getch();
return(0);
}
}
If (flag ==0)
{
Printf ("\ t \ t \ tThere is no information for this user \ n");
Printf ("\ t \ t \ tPress any key to return to the main menu \ n");
getch();
return(0);
}
return(0);
}
void deletebyphone()
{
int i,j;
int delete mark = 0;
A charging telephone [20];
Printf ("\ t \ t \ tPlease enter the phone number of the user to be deleted: \ n");
Scanf("%s ",telephone);
If (Quantity ==0)
{
Printf ("\ t \ t \ tSorry, there is no record in the file \ n");
Printf ("\ t \ t \ tPress any key to return to the main menu \ n");
getch();
Return;
}
for(I = 0; I & ltnumi++)
{
if (strcmp(student[i])。 Telephone, telephone) ==0)
{
Printf ("\ t \ t \ There is a user record you want to delete: \ n ");
Printf ("\ t \ t \ tname: %s ",student[i]。 Name);
Printf ("\ t \ t \ tTel: %s ",student[i]。 Telephone);
Printf ("\ t \ t \ taAddress:% s ",student [i]. Address);
printf("\t\t\te-mail:%s ",student[i]。 E-mail);
Printf ("\ t \ t \ tDo you want to delete it? (y/n)");
if (getch()=='y' || getch()=='Y ')
{
for(j = I; j & ltnum- 1; j++)
Student [j]= student [j+1];
num-;
delete mark++;
Printf ("\ t \ t \ tSuccessfully deleted ");
Printf ("\ t \ t \ tDo you want to continue deleting? (y/n)");
if (getch()=='y' || getch()=='Y ')
deletebyphone();
Return;
}
other
Return;
}
Continue;
}
If (delete flag ==0)
{
Printf ("\ t \ t \ tThere is no record of this user");
Printf ("\ t \ t \ tDo you want to continue deleting? (y/n)");
if(getch()=='y' || getch()=='Y ')
deletebyphone();
Return;
}
Return;
}
void deletebyname()
{
int a = 0;
int find mark = 0;
int j;
int delete mark = 0;
int I;
char name[20];
Printf ("\ t \ t \ tPlease enter the user name to delete: \ n");
Scanf("%s ",name);
for(I = a; I & ltnumi++)
{
if(strcmp(student[i])。 name,name)==0)
{
Printf ("\ t \ t \ There is a user record you want to delete: ");
find mark++;
printf(" \ t \ t \ t _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ");
Printf ("\ t \ t \ tname: %s ",student[i]。 Name);
Printf ("\ t \ t \ tTel: %s ",student[i]。 Telephone);
Printf ("\ t \ t \ taAddress:% s ",student [i]. Address);
printf("\t\t\te-mail:%s ",student[i]。 E-mail);
printf(" \ t \ t \ t _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ ");
Printf ("\ t \ t \ tDo you want to delete it? (y/n)");
if (getch()=='y' || getch() == 'Y ')
{
for(j = I; j & ltnum- 1; j++)
Student [j]= student [j+1];
num-;
delete mark++;
Printf ("\ t \ t \ tSuccessfully deleted ");
if((I+ 1)& lt; Numbers)
{
Printf ("\ t \ t \ tDo you want to continue deleting the user information with the same name? (y/n)");
if (getch()=='y ')
{
a = I;
Continue;
}
}
Printf ("\ t \ t \ tDo you want to continue deleting? (y/n)");
if (getch()=='y ')
delete byname();
Return;
}
if((I+ 1)& lt; Numbers)
{
Printf ("\ t \ t \ tDo you want to continue deleting the user information with the same name? (y/n)");
if (getch()=='y' || getch() == 'Y ')
{
a = I;
Continue;
}
}
}
other
Continue;
}
if((delete mark = = 0)& amp; & amp(findmark==0))
{
Printf ("\ t \ t \ tThere is no record of this user");
Printf ("\ t \ t \ tDo you want to continue deleting? (y/n)");
if(getch()=='y' || getch() == 'Y ')
deletebyphone();
Return;
}
else if (findmark! =0)
{
Printf ("\ t \ t \ tNo duplicate name information");
Printf ("\ t \ t \ tThere is no record of this user");
Printf ("\ t \ t \ tDo you want to continue deleting? (y/n)");
if(getch()=='y' || getch() == 'Y ')
deletebyphone();
Return;
}
}
int dele()
{
char choice;
Printf ("\ t \ t1-Delete by phone number 2- Delete by name");
Printf ("\ t \ t \ tPlease select:");
choice = getch();
Switch (selection)
{
case“ 1”:delete by phone(); Break;
Case "2": delete by name (); Break;
}
return(0);
}
Int sortbyname() // Sort by name
{
int i,j;
Structural records;
for(I = 1; I & ltnumi++)
{
if(strcmp(student[i])。 Name, student [i- 1]. Name)<0)
{
tmp = student[I];
j = I- 1;
do
{
Student [j+ 1]= student [j];
j-;
}while ((strcmp(tmp.name,student[j])。 Name)<0 & ampj & gt = 0);
Student [j+1] = tmp;
}
}
Printf ("\ t \ t \ tSorting succeeded. Show? (y/n)");
if (getch()=='y ')
list();
return(0);
}
int main()
{
printf(" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf(" \ t \ t * * * * * * * * * Welcome to Tongxun Road * * * * * * * * * * * * * * * * * ");
printf(" \ t \ t # # # # # # # # # # # # # code by XXXXX # # # # # # # # # # # # # # # n ");
printf(" \ t \ t * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf ("Press any key to enter the main menu \ n");
getch();
int selectnum
while( 1)
{
select num = menu _ select();
Switch (select number)
{
Case 0:
{
adduser();
Break;
}
Case 1:
{
list();
Break;
}
Case 2:
{
search by name();
Break;
}
Case 3:
{
search by phone();
Break;
}
Case 4:
{
adduser(); //Insert here, you should be able to specify the location, but it doesn't mean much, just like adding a record.
Break;
}
Case 5:
{
sort by name();
Break;
}
Case 6:
{
dele();
Break;
}
Case 7:
{
Printf ("Bye! \ n ");
System ("suspended");
getchar();
Exit (0);
}
}
}
getchar();
Returns 0;
}
If you are satisfied, please accept it.