| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 529 人关注过本帖
标题:我这个小型图书馆管理系统为什么会出现重复输出呢??
只看楼主 加入收藏
cmkboy
Rank: 1
来 自:湖北
等 级:新手上路
帖 子:13
专家分:7
注 册:2010-9-24
结帖率:100%
收藏
 问题点数:0 回复次数:0 
我这个小型图书馆管理系统为什么会出现重复输出呢??
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define PT "%-5.5s %-8.8s %-8.8s %-8.8s %.2f\n",p->number,p->title,p->writer,p->publishinghouse,p->pricing
struct book
{
    char writer[20];              /*作者名*/
    char title[20];            /*书名*/
    char publishinghouse[20];          /*出版单位*/
    char number[10];            /*书号*/
    float  pricing;                 /*价格*/
    struct book * next;  /*链表的指针域*/
};
struct book* Create_Books_Doc();/*新建链表*/

void InsertDoc(struct book* head); /*插入*/

void DeleteDoc(struct book* head );/*删除*/

void Print_Book_Doc(struct book* head);/*浏览*/

void search_book(struct book* head); /*查询*/

void info_change(struct book* head);/*修改*/


/*新建链表头节点*/
struct book* Create_Books_Doc()
{
    struct book* head;
    head=(struct book*)malloc(sizeof(struct book)); /*分配头节点空间*/
    head->next=NULL;/*头节点指针域初始化,定为空*/
        return head;
}

/*插入*/
void InsertDoc(struct book*head)
{
    struct book*s, *p;/*定义结构体指针变量 s指向开辟的新结点首地址 p为中间变量*/
    char flag='Y'; /*定义flag,方便用户选择重复输入*/
    p=head;/*遍历到尾结点,p指向尾结点*/
        while(p->next!= NULL)
        {
            p=p->next;
        }
        /*开辟新空间,存入数据,添加进链表*/
        while(flag=='Y'||flag=='y')
        {
            s=(struct book*)malloc(sizeof(struct book));
            printf("\n             请输入图书登陆号:");
            scanf("%s",s->number);
            printf("\n            请输入图书书名:");
            scanf("%s",s->title);
            printf("\n             请输入图书作者名:");
            scanf("%s",s->writer);
            printf("\n            请输入图书出版社:");
            scanf("%s",s->publishinghouse);
            printf("\n            请输入图书价格:");
            scanf("%f",&s->pricing);
            printf("\n");
            p->next=s;/*将新增加的节点添加进链表*/
            p=s;/*p指向尾节点,向后移*/
            s->next=NULL;printf(" ━━━━ 添加成功!━━━━");
            printf("\n继续添加?(Y/N):");
            scanf("%c",&flag);
            printf("\n");
            if(flag=='N'||flag=='n')
            {
                break;
            }
            else
                if(flag=='Y'||flag=='y')
                {
                    continue;
                }
                return;
        }
}

/*查询操作*/
void search_book(struct book*head)
{
    struct book* p;
    char temp[20];
    p=head;
    if(head==NULL || head->next==NULL) /*判断图书库是否为空*/
    {
        printf(" ━━━━ 图书库为空!━━━━\n");
    }
    else
    {
        printf("请输入您要查找的书名: ");
        scanf("%s",temp);
        /*指针从头节点开始移动,遍历至尾结点,查找书目信息*/
        while(p->next!= NULL)
        {
            p=p->next;
            if(strcmp(p->title,temp)==0)
            {
                printf("\n图书已找到!\n");
                printf("\n");
                printf("登录号: %s\t\n",p->number);
                printf("书名: %s\t\n",p->title);
                printf("作者名: %s\t\n",p->writer);
                printf("出版单位: %s\t\n",p->publishinghouse);
                printf("价格: %.2f\t\n",p->pricing);
            }
            if(p->next==NULL)
                printf("\n查询完毕!\n");
        }
    }
}



 /*浏览操作*/
void Print_Book_Doc(struct book* head)   
{
    struct book* p;
    if(head==NULL || head->next==NULL)/*判断图书库是否为空*/
    {
        printf("\n━━━━ 没有图书记录! ━━━━\n\n");
        return;
    }
    p=head;
    printf("登录号   书名      作者   出版单位   价格\n");
    /*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/
    while(p->next!= NULL)
    {
        p=p->next;
        printf(PT); /*循环输出表格*/
    }
    printf("\n");
}

/*修改操作*/
void info_change(struct book* head)
{
    struct book* p;
    int panduan=0; /*此变量用于判断是否找到书目*/
    char temp[20];
    p=head;
    printf("请输入要修改的书名:\n");
    scanf("%s",temp);
    while(p->next!= NULL)
    {
        p=p->next;
        if(strcmp(p->title,temp)==0)
        {
        printf("\n请输入图书登陆卡号:");
        scanf("%s",p->number);
        printf("\n请输入图书书名:");
        scanf("%s",p->title);
        printf("\n 请输入图书作者名:");
        scanf("%s",p->writer);
        printf("\n 请输入图书出版社:");
        scanf("%s",p->publishinghouse);
        printf("\n请输入图书价格:");
        scanf("%f",&p->pricing);
        printf("\n");
        panduan=1;
        }
    }
    if(panduan==0)
    {
        printf("\n━━━━没有图书记录!━━━━\n\n");
    }
    return;
}

/*删除操作*/
void DeleteDoc(struct book* head)
{
    struct book*s,*p;/*s为中间变量,p为遍历时使用的指针*/
    char temp[20];
    int panduan; /*此变量用于判断是否找到了书目*/
    panduan=0;
    p=s=head;
    printf("[请输入您要删除的书名]:");
    scanf("%s",temp);/*遍历到尾结点*/
    while(p!= NULL)
    {
        if(strcmp(p->title,temp)==0)
        {
            panduan++;
            break;
        }
        p=p->next;
    }
    if(panduan==1)
    {
        for(;s->next!=p;)/*找到所需删除卡号结点的上一个结点*/
        {
            s=s->next;
        }
        s->next=p->next; /*将后一节点地址赋值给前一节点的指针域*/
        free(p);
        printf("\n ━━━━删除成功! ━━━━\n");
    }
    else /*未找到相应书目*/
    {
        printf(" 您输入的书目不存在,请确认后输入!\n");
    }
    return;
}

int main()
{
    struct book* head;
    char choice='0';
    head=NULL;
    do/*实现反复输入选择*/
    {
        printf("******************************图书管理系统************************\n\n\n");
        printf("            [1]图书信息录入\n");
        printf("            [2]图书信息浏览\n");
        printf("            [3]图书信息查询\n");
        printf("            [4]图书信息修改\n");
        printf("            [5]图书信息删除\n");
        printf("            [6]退出系统\n");
        printf("         请选择:");
        choice=getchar();                                            @@@@@@@@@@@@@@@@@
    switch(choice)
    {
    case '1':
    {
        if(head==NULL)
            {
                head=Create_Books_Doc();
            }
        InsertDoc(head);
        break;
    }
    case '2':
        {
            Print_Book_Doc(head);
            break;
        }
    case '3':
        {
            search_book(head);
            break;
        }
    case '4':
        {
            info_change(head);
            break;
        }
    case '5':
        {
            DeleteDoc(head);
            break;
        }
    case '6':
        {
            printf("\n");
            printf("感谢使用图书管理系统\n");
            break;
        }
    /*default:
        {
            printf(" ━━━━ 输入错误,请重新输入!━━━━\n");
            break;
        }*/
    }
    }while(choice!='6');
    return 0;
}
在输入1-6之外的数字,提示“输入错误,请重新输入”和图书馆管理系统两次,调试的时候发现从@@@@@@@@@过去了,就是这个弊端。
搜索更多相关主题的帖子: 图书馆 新建 
2011-01-13 09:47
快速回复:我这个小型图书馆管理系统为什么会出现重复输出呢??
数据加载中...
 
   



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

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