#include<stdio.h>
#icluude<string.h>
#include<stdlib.h>
struct Info
{
char name[32];
char tel[32];
int age;
};
typedef struct Info info;
#define SIZE 100;
int person = 0;
void welcome()
{
system("clear");
printf("\n\n\n");
printf("\t\t*********************************************\n");
printf("\t\t*********************************************\n");
printf("\t\t******** 欢迎使用 ********\n");
printf("\t\t*********************************************\n");
printf("\t\t*********************************************\n");
sleep(2);
}
void menu()
{
system("clear");
printf("\n\n\n");
printf("\t\t*********************************************\n");
printf("\t\t*********************************************\n");
printf("\t\t****1.增加信息 2.修改信息\n");
printf("\t\t****3.查找信息 4.删除信息\n");
printf("\t\t****5.显示信息 6.退出 \n");
printf("\t\t*********************************************\n");
printf("\t\t*********************************************\n");
printf("\t\t*********************************************\n");
}
void addinfo(info *i)
{
char name[32] = {0};
char tel[32] = {0};
int age = 0;
printf("请输入姓名: 电话: 年龄: \n");
scanf("%s%s%d",name,tel,&age);
strcpy(i[person].name,name);
strcpy(i[person].tel,tel);
i[person].age = age;
person ++;
}
void modifyinfo(info *i)
{
char name [32] = {0};
char tel [32] = {0};
int age = 0;
int num;
printf("请输入序号: \n");
scanf("%d",&num);
printf("请输入新的姓名: 电话: 年龄: \n");
scanf("%s%s%d",name,tel,&age);
strcpy(i[person].name,name);
strcpy(i[person].tel,tel);
i[num].age = age;
printf("修改成功! \n");
sleep(2);
}
void searchinfo(info *i)
{
char name[32] = {0};
int j;
printf("请输入需要查找人的姓名: \n");
scanf("%s",name);
for(j = 0 ; j < person ; j ++)
{
if(strcmp(name,i[j].name) == 0)
{
printf("%d %s %s \n",i[j].age,i[j].tel,i[j].name);
}
sleep(2);
}
}
void deleteinfo(info *i)
{
int place;
int j;
printf("请输入要删除的联系人序号: \n");
scanf("%d",&place);
for(j = place;j < person; j ++)
{
strcpy(i[j].name,i[j + 1].name);
strcpy(i[j].tel, i[j + 1].name);
i[j] =i[j + 1];
}
person = person - 1;
}
void showinfo(info *i)
{
int j;
for (j = 0; j < person; j++)
{
printf("%s %s %d\n", i[j].name, i[j].tel, i[j].age);
}
sleep(2);
}
int main()
{
int choice;
info in[SIZE] = {0};
welcome();
while (1)
{
menu();
scanf("%d", &choice);
switch(choice)
{
case 1:
addinfo(in);
break;
case 2:
modifyinfo(in);
break;
case 3:
searchinfo(in);
break;
case 4:
deleteinfo(in);
break;
case 5:
showinfo(in);
break;
case 6:
exit(0);
default:
printf("Error\n");
}
}
return 0;
}
用c语言写一个简易通讯录
最新推荐文章于 2023-03-10 16:29:28 发布