7/26

今日主要是完成了通讯簿的设计 大部分功能已经完成 但

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<Windows.h>

#define N 100

struct address
{
	int num;
	char name[ N ];
	char tel[ N ];
	int time;

};

struct address list[N];

void search();
void  face();
void display1();
void display();
void add();
void del();
void reserve();
void sort();

int main()
{
	int flag=1;
	while (flag)
	{
		face();
	}

}

void face()
{
	int n;

	printf("**********************\n");
	printf("1.显示联系人\n");
	printf("2.请输入要添加的联系人\n");
	printf("3.请选择要删除的联系人\n");
	printf("4.查找数据\n");
	printf("5.修改数据\n");
	printf("6.退出程序\n");
	printf("**********************\n");

	printf("输入功能n:");
	scanf("%d",&n);
	
	switch (n)
	{
		case 1:
		display();
			break;
	case 2:
			add();
			break;
		case 3:
		del();
		break;

	case 4:
		search();
		break;
	case 5:
		reserve();
		break;
	case 6:
		sort();
		break;
	case 7:
		exit(1);
		break;
	default:
		printf("请输入正确的功能按键\n");
		face();
		break;
	}
		


}

void add()
{
	int i=0,j;
	char n[N];
	char t[N];
	lopp:printf("请输入姓名和电话:\n");
	scanf("%s %s",&n,&t);
	
	strcpy(list[i].name,n);
	strcpy(list[i].tel,t);
	list[i].num=i+1;
	//printf("%s\n",list[i].name);
	//printf("%s\n",list[i].tel);
	i++;
	list[0].time=i;//确定输入数据个数
	

	lopa:printf("是否继续录入 1 是,2 否\n请输入功能:");
	scanf("%d",&j);
	if(j == 1)
	{
		goto lopp;
	}
	else if (j == 2)
	{
		face();
	}
	else
	{
		goto lopa;
	}
	
}

void display1()
{
	int i;

	for (int i = 0; i < list[0].time; i++)
	{
		printf("%d. ",list[i].num);
		printf("%s ",list[i].name);
		printf("%s\n",list[i].tel);
		
	}
}

void display()
{
	int a;
	display1();
	printf("按1返回主界面:");
	scanf("%d",&a);
	if (a == 1)
	{
		face();
	}

}

void del()
{
	int i,n;

	display1();

	printf("请选择要删除的数据n:");
	scanf("%d",&n);
	
	for (int i = n-1; i <list[0].time; i++)
	{
		list[i].num = list[i+1].num-1;
		strcpy(list[i].name,list[i+1].name);
		strcpy(list[i].tel,list[i+1].tel);
	}	
	//strcpy(list[i].name,"");
	//	strcpy(list[i].tel,"");
	list[0].time--;
	display1();
	printf("\n");
	face();

}

void search()
{
	int i,n,lenth,j,p;
	char news[N];

	printf("按1姓名检索 按2电话检索:");
	scanf("%d",&n);
	printf("请输入想要查找的对象的信息n: ");
	scanf("%s",&news);
	lenth = strlen(news);

	if (1 == n)
	{

		for (int i = 0; i < list[0].time; i++)
		{
			char *p=list[i].name;
			char *q = news;
			for (int j= 0; j < 20; j++)
			{
				if(strncmp(p+j,q,lenth) == 0)
				{
					printf("%d. ",list[i].num);
					printf("%s ",list[i].name);
					printf("%s\n",list[i].tel);
					printf("\n");
					break;
				}
				
			}



		}
	}

	else if (2 == n)
	{

		for (int i = 0; i < list[0].time; i++)
		{
			char *p=list[i].tel;
			char *q = news;
			for (int j= 0; j < 20; j++)
			{
				if(strncmp(p+j,q,lenth) == 0)
				{
					printf("%d. ",list[i].num);
					printf("%s ",list[i].name);
					printf("%s\n",list[i].tel);
					printf("\n");
					break;
				}
				
			}
		}
	}

	else if (n != 1 && n!=2)
	{
		printf("请输入正确的的功能");
		search();
	}

	face();



}

void reserve()
{
	int i,j,b;
	char a[N];
	
	display1();
	printf("请选择要修改的项目");
	scanf("%d",&i);

	printf("%d. ",list[i-1].num);
	printf("%s ",list[i-1].name);
	printf("%s\n",list[i-1].tel);

	printf("请选择要更改的数据 1 姓名 2 电话 ");
	scanf("%d",&j);

	if (j == 1)
	{
		scanf("%s",a);
		strcpy(list[i-1].name,a);
	
	}
	if (j == 2)
	{
		scanf("%s",a);
		strcpy(list[i-1].tel,a);
	
	}
	printf("%d. ",list[i-1].num);
	printf("%s ",list[i-1].name);
	printf("%s\n",list[i-1].tel);

	printf("是否继续修改信息1 是 2 返回主界面");
	scanf("%d",&b);
	if (b == 1)
	{
		reserve();
	}

	if (2)
	{
		face();
	}

	


}

void sort()
{


}


还有不规范的地方

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值