说实话没有看懂楼主的思路,所以就按自己的想法稍微改了一下#include<stdio.h>
#include<string.h>
struct Person
{
char name[40];
int phone;
}Per;
void menu();
void addPerson(struct Person *Per,int *size);
void reseach(struct Person *Per,int *size);
void addPerson(struct Person *Per,int *size)
{
struct Person P;
putchar('\n');
printf("please input the name:\n");
scanf_s("%s", P.name,128);
printf("please input the phone number:\n");
scanf_s("%d", &(P.phone));
Per[*size] = P;
(*size) ++;
printf("添加完成!\n");
}
void reseach(struct Person *Per,int *size)
{
int i;
for (i=0;i<*size;i++)
{
printf("联系人%d:%s\n", *size,Per[i].name);
printf("电话号码:%d\n", Per[i].phone);
}
}
void menu()
{
printf("--------------------------\n");
printf("----欢迎来到本查询系统----\n");
printf(" 查询联系人:1\n");
printf(" 添加联系人:2\n");
printf(" 更改联系人:3\n");
printf(" 退出查询系统:4\n");
printf("--------------------------\n");
printf("--------------------------\n");
}
int main(void)
{
int i=0;
struct Person Per[100];
int size = 0;
while (1)
{
menu();
printf("请输入想要执行的命令:");
scanf_s("%d", &i);
switch(i)
{
case 1:reseach(Per,&size);
break;
case 2:addPerson(Per,&size);
break;
case 3:printf("当前系统正在升级中:\n"); break;
case 4:printf("欢迎使用本查询系统! \n"); return 0;
default:printf("请重新输入对应的命令!\n"); break;
}
}
return 0;
}
|