```c
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
typedef struct
{
char name[20];
char sex[5];
char folk[5];
char birth[10];
char add[20];
char id[20];
}Person;
Person ID[100];
int menu_select()
{ char c;
do{system("cls");
printf("\n\t\t %c%c%c%c%c%c%cIdentityConctrol System%c%c%c%c%c%c%c\n\n\n",3,3,3,3,3,3,3,3,3,3,3,3,3,3);
printf ("\t%c 1.Input date \n\n",21);
printf ("\t%c 2.Display date \n\n",21);
printf ("\t%c 3.Sort the people by birth \n\n",21);
printf ("\t%c 4.Insert an ID \n\n",21);
printf ("\t%c 5.Delete an ID \n\n",21);
printf ("\t%c 6.Search an ID by name \n\n",21);
printf ("\t%c 7.Count the people \n\n",21);
printf ("\t%c 8.Copy date from file \n\n",21);
printf ("\t%c 9.Write date to file \n\n",21);
printf ("\t%c 0.exit \n\n",21);
printf(" (0-9):");
c=getchar();
}while(c<'0'||c>'9');
return(c-'0');
}
int input(PersonID[],int n);
{int i=0;
charsign='w',x[10];system("cls");
printf("\tInputthe date:\n");
while(sign!='n'&&sign!='N')
{
printf("\tName:");
scanf("%s",&ID[n+i].name);
printf("\tSex:");
scanf("%s",&ID[n+i].sex);
printf("\tFolk:");
scanf("%s",&ID[n+i].folk);
printf("\tbirth:");
scanf(" %s",&ID[n+i].birth );
printf("\tAddress:");
scanf(" %s",&ID[n+i].add);
printf("\tID:");
scanf(" %s",&ID[n+i].id);
gets(x);
printf(" Are you sure to continue?(Y/N)\n");
scanf(" %c",&sign);
i++;
}
return(n+i);
}
voiddisplay(Person ID[],int n)
{
inti;system("cls");
printf("---------------------------------------------------------------------\n");
printf("name sex folk birth add id \n");
printf("---------------------------------------------------------------------\n");
for(i=1;i<n+1;i++)
{
printf("%-10s%-10s%-10s%-15s%-15s%-15s\n",ID[i-1].name,ID[i-1].sex,ID[i-1].folk,ID[i-1].birth,ID[i-1].add,ID[i-1].id);
if(i>1&&i%10==0)
{printf("----------------------------------------------------------------\n");
system("pause");
printf("---------------------------------------------------------------\n");
}
}
system("pause");
}
voidsort_by_birth(Person ID[],int n)
{
int i,j;
chart[20];system("cls");
for(i=0;i<n-1;i++)
for(j=0;j<n-1-i;j++)
if(strcmp(ID[j].birth,ID[j+1].birth)>0)
{strcpy(t,ID[j+1].name);
strcpy(ID[j+1].name,ID[j].name);
strcpy(ID[j].name,t);
strcpy(t,ID[j+1].sex);
strcpy(ID[j+1].sex,ID[j].sex);
strcpy(ID[j].sex,t);
strcpy(t,ID[j+1].folk);
strcpy(ID[j+1].folk,ID[j].folk);
strcpy(ID[j].folk,t);
strcpy(t,ID[j+1].birth);
strcpy(ID[j+1].birth,ID[j].birth);
strcpy(ID[j].birth,t);
strcpy(t,ID[j+1].add);
strcpy(ID[j+1].add,ID[j].add);
strcpy(ID[j].add,t);
strcpy(t,ID[j+1].id);
strcpy(ID[j+1].id,ID[j].id);
strcpy(ID[j].id,t);
}
}
int insert_an_id(PersonID[],int n)
{
charx[100];system("cls");
printf("\n\tName:");
scanf("%s",&ID[n].name);
printf("\tSex:");
scanf("%s",&ID[n].sex);
printf("\tFolk:");
scanf("%s",&ID[n].folk);
printf("\tbirth:");
scanf("%s",&ID[n].birth);
printf("\tAddress:");
scanf(" %s",&ID[n].add);
printf("\tID:");
scanf(" %s",&ID[n].id);
gets(x);
n++;
sort_by_birth(ID,n);
printf("\n");
return(n);
}
intdelete_an_id(Person ID[],int n)
{
char s[20];
inti=0,j;system("cls");
printf("Personname you want to delete :\n");
scanf("%s",s);
while(strcmp(ID[i].name,s)!=0&&i<n)i++;
if(i==n)
{
printf("Sorry,there is no such a person \n");
return(n);
}
for(j=i;j<n-1;j++)
{
strcpy(ID[j].name,ID[j+1].name);
strcpy(ID[j].sex,ID[j+1].sex);
strcpy(ID[j].folk,ID[j+1].folk);
strcpy(ID[j].birth,ID[j+1].birth);
strcpy(ID[j].add,ID[j+1].add);
strcpy(ID[j].id,ID[j+1].id);
}
printf("Delete ID successfully \n");
return(n-1);
}
voidsearch_by_name(Person ID[],int n)
{ char s[20];
inti=0;system("cls");
printf(" Whatis the name you want to find:");
gets(s);
while(strcmp(ID[i].name,s)!=0&&i<n)i++;
if(i==n)
{
printf("Sorry,thereis no such a person \n");
system("pause");
return(n);
}
printf("name sex folk birth add id \n");
printf("%-10s%-10s%-10s%-15s%-15s%-15s\n",ID[i].name,ID[i].sex,ID[i].folk,ID[i].birth,ID[i].add,ID[i].id);
system("pause");
}
void count(PersonID[],int n)
{ charstr1[5],str2[5],str3[5];
inti,j=0,p,q,r;system("cls");
printf("pleaseenter the current year:\n");
gets(str1);
p=atoi(str1);
printf("pleaseenter the age you want to count:\n");
gets(str3);
r=atoi(str3);
printf("name sex folk birth add id \n");
for(i=0;i<n;i++)
{ strncpy(str2,ID[i].birth,4);
q=atoi(str2);
if((p-q)==r)
printf("%-10s%-10s%-10s%-15s%-15s%-15s\n",ID[i].name,ID[i].sex,ID[i].folk,ID[i].birth,ID[i].add,ID[i].id);
j++;
}
printf("Thereare %d person about this age.\n",j);
system("pause");
}
intaddfromText(Person ID[],int n)
{
int i=0,num;
FILE *fp;
char filename[20];
printf("Enter the file name :\n");
scanf(" %s",filename);
if((fp=fopen(filename,"rb"))==NULL)
{
printf("Cannot open the file : \n");
system("pause");
return(n);
}
fscanf(fp,"%d",&num);
while(i<num)
{
fscanf(fp,"%s%s%s%s%s%s",ID[n+i].name,ID[n+i].sex,ID[n+i].folk,ID[n+i].birth,ID[n+i].add,ID[n+i].id);
i++;
}
n+=num;
fclose(fp);
printf("\n");
printf(" Readsuccessfully \n");
system("pause");
return(n);
}
voidwritetotext(Person ID[],int n)
{
int i=0;
FILE *fp;
charfilename[100];
printf("Enter a filename: \n");
scanf(" %s",filename);
if((fp=fopen(filename,"w"))==NULL)
{
printf("Cannot open the file : \n");
system("pause");
return;
}
fprintf(fp,"%d\n",n);
while(i<n)
{
fprintf(fp,"%s%s%s%s%s%s",ID[i].name,ID[i].sex,ID[i].folk,ID[i].birth,ID[i].add,ID[i].id);
i++;
}
fclose(fp);
printf("Writedate to file successfully\n");
}
void main()
{
int n=0;
for(;;)
{
switch(menu_select())
{
case 1:
printf(" Input the ID of the person:\n");
n=input(ID,n);
break;
case 2:
display(ID,n);
break;
case 3:
printf("Date sort by birth:\n");
sort_by_birth(ID,n);
display(ID,n);
break;
case 4:
printf("Insert an ID: \n");
n=insert_an_id(ID,n);
display(ID,n);
break;
case 5:
printf("Delete an ID: \n");
n=delete_an_id(ID,n);
break;
case 6:
printf("Searth an ID by name: \n");
search_by_name(ID,n);
break;
case 7:
printf("count the age of people:\n");
count(ID,n);
break;
case 8:
printf("Copy date from file:\n ");
addfromText(ID,n);
break;
case 9:
printf("write date to file:\n \n");
writetotext(ID,n);
break;
case 0: system("cls");
printf("\n\n\t\tThank you !");
system("pause");exit(0);
}
}
}
```