:
#include
#include
# define N 108
Typedef struct telephone
{
Char name [25];
Char num [25];
Char tel [25];
} TEL;
Void DisplayMenu ();//display the main menu
Void the save (TEL a [], int n);
Void CreateList (TEL a [], int n);//1. Create a directory
Void DisplayList (TEL a [], int n);//2. According to the address book
Void InquireListName (TEL a [], int n);////3. The name query address book
Void InquireListNum (TEL a [], int n);//4. According to the student number query address book
Void ChangeListName (TEL a [], int n);//5. According to the name change address book
Void ChangeListNum (TEL a [], int n);//6. According to the student id to modify address book
Int DelListName (TEL a [], int n);//7. According to the name delete the address book
Int DelListNum (TEL a [], int n);//8. According to the student id to delete the address book
Void UpSortListName (TEL a [], int n);//9. Name ascending order address book
Void DownSortListNum (TEL a [], int n);//10. Student id reverse ordering address book
Int AddList (TEL a [], int n);//11. Add student information
Int main ()
{
Struct telephone a, [N].
Int I, n;
The FILE * fp.
If ((fp=fopen (" stu. Dat ", "r"))!=NULL)//if the file is stu. Dat existing
{//the data from a file is loaded into the array (read the record number n and n name, student id, phone number)
The fscanf (fp, "% d", & amp; n);
for(i=0; iFscanf (fp, "% s % s % s", a name, a [I] num, a [I]. Tel);
}
The else
{
Printf (" first use of the system, please enter n and n name, student number, telephone number: \ n ");
The scanf (" % d ", & amp; n);
for(i=0; iThe scanf (" % s % s % s ", a [I]. Name, a [I] num, a [I]. Tel);
Save (a, n);
}
DisplayMenu ();//display the main menu
While (1)
{
Char select;
Char name [25];
The scanf (" % c ", & amp; Select);
If (select<'a' | | select> 'l')
{
Printf (" input error! \n");
continue;
}
//if (select=='l')
//break;
The switch (select)
{
Case 'a' :
DisplayMenu ();//display the main menu
break;
Case 'b' :
DisplayList (a, n);//2. According to the address book
break;
Case 'c' :
InquireListName (a, n);//3. The name query address book
break;
Case 'd' :
InquireListNum (a, n);//4. According to the student number query address book
break;
Case 'e' :
ChangeListName (a, n);//5. According to the name change address book
break;
Case 'f' :
ChangeListNum (a, n);//6. According to the student id to modify address book
break;
Case 'g' :
If (DelListName (a, n))//7. According to the name delete address book
N -;
break;
Case 'h' :
If (DelListNum (a, n))//8. According to the student id to delete address book
N -;
break;
In case the 'I' :
UpSortListName (a, n);//9. Name ascending order address book
break;
Case 'j' :
DownSortListNum (a, n);//10. Student id reverse ordering address book
break;
Case 'k' :
If (AddList (a, n))//11. Add student information
N++;
Save (a, n);
break;
Case 'l' :
exit(0);//12.
exit systembreak;
}
}
return 0;
}
Void the save (TEL a [], int n)
{
int i;
The FILE * fp.
Fp=fopen (" stu. Dat ", "w");
Fprintf (fp, "% d \ n", n);
for(i=0; iFprintf (fp, "% s \ n \ \ t t % s % s", a [I]. Name, a [I] num, a [I]. Tel);
}
Void DisplayMenu ()//1. According to the main menu
{
Printf (" student address book management system \ n \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * system function menu * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - \ n ");
Printf (" b. a. according to the main menu display directory \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" c. by name query directories d. according to the student number query directory \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" f. e. according to the name change directories by student number change directory \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" g. by name delete directories h. according to the student id to delete contacts \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" i. name ascending sort directories j. student id reverse order directory \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n ");
Printf (" k. add student information l. exit system \ n ");
Printf (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - \ n ");
Printf (" * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * \ n \ n ");
Printf (" please choose you need operation: \ n ");
}
Void DisplayList (TEL a [], int n)//2. The show directory
{
int i;
Printf (" shows the address book: \ n ");
for(i=0; iPrintf (" % s \ n \ \ t t % s % s ", a [I]. Name, a [I] num, a [I]. Tel);
printf("\n");
}
Void InquireListName (TEL a [], int n)//3. The name query address book
{
Int I, flag;
Char SearchName [25];
Printf (" by name query directories: \ n ");
The scanf (" % s ", SearchName);
For (I=0, flag=0; i{
If (STRCMP (SearchName, a [I] name)==0)
{
Printf (" % s \ t, "a [I] name);
Printf (" % s \ t, "a [I] num);
Printf (" % s \ n ", a [I]. Tel);
Flag=1;
break;
}
}
If (flag==0)
{
Printf (" not query to the name information! \n");
}
printf("\n");
}
Void InquireListNum (TEL a [], int n)//4. According to the student number query address book
{
Int I, flag;
Char SearchID [25];
Printf (" according to the student number query directories: \ n ");
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull