• C语言实现通讯录


    <span style="font-size:18px;">#include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<malloc.h>
    #include<conio.h>
    #define LEN sizeof(struct ab)
    #define ZIP 7
    #define PHONE 7
    #define MAX 100
    struct ab
    {
    	char name[10];
    	char addr[10];
    	char zip[ZIP];
    	char phone[PHONE];
    	struct ab *next;
    };
    struct ab *head;
    void search(struct ab *head);
    struct ab *add(struct ab *head);
    struct ab *del(struct ab *head);
    void alter(struct ab *head);
    void print(struct ab *head);
    void thefirst();
    int n;</span>
    <span style="font-size:18px;">#include"head.h"
    void main()
    {
    	n=0;
    	head=(struct ab *)malloc(LEN);
    	thefirst();
    }
    void thefirst()
    {
    	char c;
    	system("CLS");
    	puts("**************************************");
    	puts("                 通讯录               ");
    	puts("                1、查询               ");
    	puts("                2、加入               ");
    	puts("                3、删除               ");
    	puts("                4、改动               ");
    	puts("                5、显示               ");
    	puts("                6、返回               ");
    	puts("**************************************");
    	c=getch();
    	system("CLS");
    	switch(c)
    	{
    		case '1':search(head);break;
    		case '2':head=add(head);thefirst();break;
    		case '3':head=del(head);thefirst();break;
    		case '4':alter(head);break;
    		case '5':print(head);break;
    		case '6':printf("BYE BYE!
    ");
    	}
    }</span>

    <span style="font-size:18px;">#include"head.h"
    void search(struct ab *head)
    {
    	char str[10];
    	struct ab *p;
    	p=head;
    	printf("please input the name you want to search!
    ");
    	scanf("%s",str);
    	if(p==NULL)
    	{
    		printf("please input the information first!press any key to thefirst 
    ");
    		getch();
    		thefirst();
    	}
    	system("CLS");
    	for(;p&&strcmp(str,p->name);p=p->next);
    	if(p)
    		printf("%10s
    %10s
    %10s
    %10s
    ",p->name,p->addr,p->zip,p->phone);
    	else
    		printf("there is no information about the people you want!
    ");
    	getch();
    	thefirst();
    }</span>

    <span style="font-size:18px;">#include"head.h"
    struct ab *add(struct ab *head)
    {
    	struct ab *p1,*p2,*p3;
    	char c[10];
    	printf("please input the name!
    ");
    	scanf("%s",c);
    	p1=head;
    	if(n==0)
    	{
    		strcpy(p1->name,c);
    		printf("please input the address!
    ");
    		scanf("%s",p1->addr);
    		printf("please input the zip!
    ");
    		scanf("%s",p1->zip);
    		printf("please input the phone!
    ");
    		scanf("%s",p1->phone);
    		printf("%s
    ",p1->phone);
    		p1->next=NULL;
    		n++;
    	}
    	else
    	{	
    		p3=(struct ab *)malloc(LEN);
    		strcpy(p3->name,c);
    		printf("please input the address!
    ");
    		scanf("%s",p3->addr);
    		printf("please input the zip!
    ");
    		scanf("%s",p3->zip);
    		printf("please input the phone!
    ");
    		scanf("%s",p3->phone);
    		if(strcmp(c,p1->name)<0)
    		{
    			head=p3;
    			p3->next=p1;
    		}
    		else
    		{
    			for(;p1&&strcmp(c,p1->name)>0;p2=p1,p1=p1->next);
    			if(p1==NULL)
    			{
    				p2->next=p3;
    				p3->next=NULL;
    			}
    			else
    			{
    				p2->next=p3;
    				p3->next=p1;
    			}
    			n++;
    		}
    	}
    	return head;
    }</span>

    <span style="font-size:18px;">#include"head.h"
    struct ab *del(struct ab *head)
    {
    	struct ab *p1,*p2;
    	char c[10];
    	p1=head;
    	printf("please input the name you want to delete
    ");
    	scanf("%s",c);
    	for(;p1&&strcmp(c,p1->name);p2=p1,p1=p1->next);
    	if(p1==NULL)
    	{
    		printf("not find!press any key to thefirst 
    ");
    		getch();
    	}
    	else if(p1==head)
    		head=p1->next;
    	else
    		p2->next=p1->next;
    	return head;
    }</span>

    <span style="font-size:18px;">#include"head.h"
    void alter(struct ab *head)
    {
    	char str[10];
    	struct ab *p;
    	p=head;
    	printf("please input the name you want to search!
    ");
    	scanf("%s",str);
    	for(;p&&strcmp(str,p->name);p=p->next);
    	if(p)
    	{
    		printf("please input the address!
    ");
    		scanf("%s",p->addr);
    		printf("please input the zip!
    ");
    		scanf("%s",p->zip);
    		printf("please input the phone!
    ");
    		scanf("%s",p->phone);
    	}
    	else 
    	{
    		printf("not find!press any key to thefirst 
    ");
    		getch();
    	}
    	thefirst();
    }
    </span>

    <span style="font-size:18px;">#include"head.h"
    void print(struct ab *head)
    {
    	struct ab *p;
    	for(p=head;p;p=p->next)
    	{
    		printf("%10s%10s%10s%10s
    ",p->name,p->addr,p->zip,p->phone);
    	}
    	getch();
    	thefirst();
    }</span>


  • 相关阅读:
    [转]Greenplum的工作负载及资源管理
    [转]Tomcat中的Session小结
    [转]Class.forName()的作用与使用总结
    [转]如何在 Git 里撤销(几乎)任何操作
    [转]session和cookie的区别和联系,session的生命周期,多个服务部署时session管理
    piwik获取访客头像,自定义显示访问者头像(URL)和描述(标题和替代)
    php解析url并得到url中的参数及获取url参数
    php结合phantomjs实现网页截屏、抓取js渲染的页面
    利用PhantomJS进行网页截屏,完美解决截取高度的问题
    多线程编程
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/4238584.html
Copyright © 2020-2023  润新知