标题:【链表】编写通讯录管理程序
取消只看楼主
feiyuanyong
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2013-11-24
结帖率:25%
已结贴  问题点数:10 回复次数:1 
【链表】编写通讯录管理程序
下面是我编写的程序,为啥直接不让输入啊?
//=============================================================================
//文件名:E
//功能说明: 【链表】编写通讯录管理程序:
// 每个人有姓名、固定电话、移动电话、邮编和通讯地址等信息,要求:
//(1)至多存储 50 个人的信息;
//(2)提供录入、删除、修改和查询的功能;
//(3)删除、修改和查询的时提示用户输入姓名,找到对应位置后进行相关操作.
//作者:
//时间:13.12.15
//备注:
//=============================================================================

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define _CRT_SECURE_NO_WARNINGS
#define LEN sizeof(struct Info)
#define  _CRT_SECURE_NO_WARNINGS

typedef struct Info
{
    char names[21];
    long tel_num;
    long mob_num;
    char mail[20];
    char add[100];
    struct Info *next;
}Info;

//==============================函数声明================================
//========================================================
//函数名:seek
//功能说明:查找信息
//参数:people[]---输入的信息,count---输入的人数
//返回值:void
//=========================================================
void seek(Info *head,int count);

//========================================================
//函数名:del
//功能说明:删除
//参数:people[]---输入的信息,count---输入的人数
//返回值:void
//=========================================================
Info* del(Info *head);

//========================================================
//函数名:modify
//功能说明:修改
//参数:people[]---输入的信息,count---输入的人数
//返回值:void
//=========================================================
Info* modify(Info *head);

//===============================主函数=================================
int main()
{
    Info *head;
    Info *p1,*p2;
    int i=0;
    char index;
    char judge;

    head=p2=(Info*)malloc(LEN);
    p1=(Info*)malloc(LEN);
    p1=p2->next;

    printf("请输入不超过50个联系人的信息!\n");  //录入信息
    while(1)
    {   
        printf("请输入姓名:");
        scanf("%s",p1->names);
        getchar();

        printf("请输入固定电话号码:");
        scanf("%ld",&p1->tel_num);

        printf("请输入移动电话号码:");
        scanf("%ld",&p1->mob_num);

        printf("请输入邮箱信息:");
        scanf("%s",p1->mail);
        getchar();

        printf("请输入通讯地址:");
        scanf("%s",p1->add);
        getchar();

        printf("\n");

        i++;            //完成一次人数加一

        p2=p1;
        p1=(Info *)malloc(LEN);
        p2->next=p1;

        printf("是否继续增加联系人(回答Y/N):");
        scanf("%c",&judge);
        getchar();

        if(judge=='N')
        {
            free(p1);
            p2->next=NULL;
            printf("\n");
            break;
        }

        printf("\n");

    }
        printf("请按照数字选择要执行的任务:1.查询,2.删除,3.修改,4.无操作!\n");//执行任务
    while(1)
    {
        printf("请选择要执行的任务:");
        scanf("%c",&index);
        getchar();

        switch(index)
        {
            case '1':seek(head,i);break;
            case '2':del(head,i);break;
            case '3':modify(head,i);break;
            case '4':break;
        }

        printf("是否继续任务(Y/N)?:");
        scanf("%c",&judge);
        getchar();
        if(judge=='N')
        {
            break;
        }
    }

    return 0;
}

//==============================函数定义========================================
//========================================================
//函数名:seek
//功能说明:查找信息
//参数:people[]---输入的信息,count---输入的人数
//返回值:void
//=========================================================
void seek(Info *head,int count)
{
    Info *p1,*p2;
    char names[21];
    int i=0;

    p2=head;
    p1=p2->next;

    printf("请输入所要查询人的姓名:");
    scanf("%s",names);
    getchar();
   
    while(p1!=NULL)
    {
        if(strcmp(p1->names,names)==0)
        {
            printf("固定电话:%d\n",p1->tel_num);
            printf("移动电话:%d\n",p1->mob_num);
            printf("邮编:%s\n",p1->mail);
            printf("通讯地址:%s\n",p1->add);
        }

        i++;
        p2=p1;
        p1=p2->next;

    }

    if(i==count)
    {
        printf("查无此人!\n");
    }
}

//========================================================
//函数名:del
//功能说明:删除
//参数:people[]---输入的信息,count---输入的人数
//返回值:void
//=========================================================
Info* del(Info *head/*,int count*/)
{
    Info *p1,*p2;
    char names[21];
    /*int i=0;*/

    p2=head;
    p1=p2->next;

    printf("请输入所要删除的人的姓名:");
    scanf("%s",names);
    getchar();
   
    while(p1!=NULL)
    {
        if(strcmp(p1->names,names)==0)
        {
            p2->next=p1->next;
            free(p1);
            p1=p2;        //重新让p1指向p2指向的位置
            printf("删除成功!\n");
        }
        p2=p1;
        p1=p2->next;
    }

    /*if(i==count)
    {
        printf("查无此人!\n");
        return;
    }*/
    return head;
}

//========================================================
//函数名:modify
//功能说明:修改
//参数:people[]---输入的信息,count---输入的人数
//返回值:void
//=========================================================
Info* modify(Info *head)
{
    Info *p1,*p2;
    char names[21];
    char judge;

    p2=head;
    p1=p2->next;

    printf("请输入所要修改的人的姓名:");
    scanf("%s",names);
    getchar();

    while(p1!=NULL)
    {
        if(strcmp(p1->names,names)==0)
        {
            printf("原固定电话:%d\n",p1->tel_num);
            printf("是否修改此项(Y/N)?:");
            scanf("%c",&judge);
            getchar();
            if(judge=='Y')
            {
                printf("请重新输入:");
                scanf("%ld",&p1->tel_num);
                getchar();
                printf("修改成功!\n");
            }
            

            printf("原移动电话:%d\n",p1->mob_num);
            printf("是否修改此项(Y/N)?:");
            scanf("%c",&judge);
            getchar();
            if(judge=='Y')
            {
                printf("请重新输入:");
                scanf("%ld",&p1->mob_num);
                getchar();
                printf("修改成功!\n");
            }
            

            printf("邮编:%s\n",p1->mail);
            printf("是否修改此项(Y/N)?:");
            scanf("%c",&judge);
            getchar();
            if(judge=='Y')
            {
                printf("请重新输入:");
                scanf("%s",p1->mail);
                getchar();
                printf("修改成功!\n");
            }
            

            printf("原通讯地址:%s\n",p1->add);
            printf("是否修改此项(Y/N)?:");
            scanf("%c",&judge);
            getchar();
            if(judge=='Y')
            {
                printf("请重新输入:");
                scanf("%s",p1->add);
                getchar();
                printf("修改成功!\n");
            }
        }
    }
}
搜索更多相关主题的帖子: 管理程序 固定电话 移动电话 通讯录 信息 
2013-12-16 22:07
feiyuanyong
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2013-11-24
得分:0 
回复 楼主 feiyuanyong
求大神!!!
2013-12-16 22:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-425291-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.164797 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved