#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define SIZE 100
struct Info
{
char name[32];
char sex;
char tel[32];
char address[32];
int age;
};
typedef struct Info info;
int person = 0;
void welcome()
{
system("clear");
printf("\n\n\n");
printf("\t\t***************************\n");
printf("\t\t***************************\n");
printf(" 欢迎使用简易通讯录\n");
printf("\t\t***************************\n");
printf("\t\t***************************\n");
sleep(1);
}
void menu()
{
system("clear");
printf("\n\n\n");
printf("\t\t***************************\n");
printf("\t\t***************************\n");
printf("\t\t1、添加联系人 2、查找联系人\n");
printf("\t\t3、修改联系人 4、删除联系人\n");
printf("\t\t5、显示联系人 6、退出\n");
printf("\t\t***************************\n");
printf("\t\t***************************\n");
}
void addinfo(info *u)
{
char name[32] = {0};
char sex;
char tel[32] = {0};
char address[32] = {0};
int age = 0;
printf("请输入姓名、性别、电话、地址、年龄:\n");
scanf("%s%s%d",name,sex,tel,address,&age);
strcpy(u[person].name,name);
u[person].sex = sex;
strcpy(u[person].tel,tel);
strcpy(u[person].address,address);
u[person].age = age;
person++;
}
void searchinfo(info *u)
{
int i, count = 1;
char name[32] = {0};
printf("请输入姓名:");
scanf("%s",name);
printf("姓名为%s的联系人有:\n",name);
for(i = 0;i < person;i++)
{
if (strcmp(u[i].name,name) == 0)
{
printf("%d : %s %s %d %c %s\n", count,u[i].name,u[i].sex,u[i].tel,u[i].address,u[i].age);
count ++;
}
}
if(count ==1)
{
printf("查无此人\n");
}
sleep(5);
}
void modifyinfo(info *u)
{
int person_m;
int choice,newage;
char str[32] = {0};
char ch;
printf("请输入需要修改的联系人的序号:");
scanf("%d",&person_m);
printf("\t\t\t******************************\n");
printf("\t\t\t可以修改的内容是:\n");
printf("\t\t\t 1、姓名 2、性别\n");
printf("\t\t\t 3、电话 4、年龄\n");
printf("\t\t\t 5、家庭住址 6、取消\n");
printf("\t\t\t******************************\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("请输入新的姓名:\n");
scanf("%s",str);
printf("%s",str);
strcpy(u[person_m].name,str);
break;
case 2:
printf("请输入新的性别:\n");
scanf("%s,str");
printf("%s",str);
u[person_m - 1].sex = ch;
break;
case 3:
printf("请输入新的电话:\n");
scanf("%s",str);
printf("%s",str);
strcpy(u[person_m - 1].tel,str);
break;
case 4:
printf("请输入新的年龄:\n");
scanf("%s,str");
printf("%s",str);
u[person_m - 1].age = newage;
break;
case 5:
printf("请输入新的住址:\n");
scanf("%s",str);
printf("%s",str);
strcpy(u[person_m].address,str);
break;
case 6:
break;
default:
printf("ERROR");
}
sleep(5);
}
void deleteinfo(info *u)
{
int u_delete;
printf("请输入需要删除联系人的序号:");
scanf("%d",&u_delete);
for(i = u_delete - 1;i < person - u_delete;i++)
{
strcpy(u[i].name,u[i+1].name);
u[i].sex = u[i + 1].sex;
strcpy(u[i].tel,u[i + 1].tel);
u[i].age = u[i + 1].age;
strcpy(u[i].address.u[i + 1]address);
}
person = person - 1;
}
void showinfo(info *u)
{
int j;
for(j = 0;j < person; j++)
{
printf("%s %s %d\n"u[j].name, u[i].sex,u[j].tel ,u[j].age,u[i].address);
}
sleep(3);
}
int main()
{
int choice;
info member[SIZE] = {0};
welcome();
while(1)
{
menu();
scanf("%d",&choice);
switch(choice)
{
case 1:
addinfo(member);
break;
case 2:
searchinfo(member);
break;
case 3:
modifyinfo(member);
break;
case 4:
deleteinfo(member);
break;
case 5:
showinfo(member);
break;
case 6:
exit(0);
default:
printf("Error\n");
}
}
return 0;
}
08-16