标题:求高手帮忙找错,三个函数体哪里错了???
取消只看楼主
G梦
Rank: 1
等 级:新手上路
帖 子:48
专家分:7
注 册:2012-12-27
结帖率:88.89%
已结贴  问题点数:20 回复次数:3 
求高手帮忙找错,三个函数体哪里错了???
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define LEN sizeof(struct node)
#define N 100
#define PF printf
#define SF scanf

struct books
    {
        int booknum;        //书号
        char bookname[20];//书名
        char authorname[20];//作者
        char publish[20];       //出版社
        int  price;         //价格  
    };   

struct node
{
    struct books book;
    struct node *next;
};
typedef struct node NODE;

   
NODE *luru(NODE *head)//录入函数   
{   
     
    NODE *p;
    head=NULL;
     while(1)
    {   
        char ch;
        p=(NODE*)malloc(LEN);
        PF("~~~~~~~~~~~~~~~开始输入信息~~~~~~~~~~~~~\n");
        PF("请输入书的编号:");
        SF("%d",&p->book.booknum);
        PF("\n");
        PF("请输入出版社:");
        SF("%s",&p->book.publish);
        PF("\n");
        PF("请输入图书价格:");
        SF("%d",&p->book.price);
        PF("\n");
        PF("请输入书名:");
        SF("%s",&p->book.bookname);
        PF("\n");
        PF("请输作者名:");
        SF("%s",&p->book.authorname);
        getchar( );//屏蔽回车
        PF("是否继续输入,请选择(y/n):");
        SF("%c",&ch);
            if(ch=='n')
               break;
            else
               p=p->next;
            
    }
     PF("输入信息成功!\n");
        return head;   
}

 NODE *search(NODE *head)//按书名查询
{
     char name[20];
     int pd=1;
     NODE *p;
     p=(NODE*)malloc(LEN);
     PF("请输入要查询的书名:");
     SF("%s",name);
     do
     {
         p=p->next;
         pd=strcmp(name,p->book.bookname);
     }
     while(pd=0);
     PF("%d\t%s\t%s\t%d\t%s\n",p->book.booknum,p->book.bookname,p->book.publish,p->book.price,p->book.authorname);
}

NODE *delsh(NODE *head)//按书号删除
{   
    int x;
    NODE *current,*front;
    PF("请你输入想要删除图书的书号\n");
    SF("%d",&x);  
     while(x>N)
    {
        PF("您要删除的图书信息不存在,请重新输入!\n");
    return 0;
    }
    if(head==NULL)
      PF("\n Empty.");
        else
        {
 
        current=head;
        while((x!=current->book.booknum)&&(current->next!=NULL))
        {
            front=current;
            current=current->next;
        }
        if(x==current->book.booknum)
        {
            if(current==head)
                head=current->next;
            else
                front->next=current->next;
            free(current);
            PF("删除图书信息成功!\n");
        }
        else
            PF("\n Not found.");
        }
    return head;
}

         
            
NODE *delsm(NODE *head)//按书名删除
{
   NODE *current, *front;
    char bookname;
    PF("请输入你要删除的书名:");
    SF("%s",bookname);
     
if(head==NULL)
        PF("\n Empty.");
    else
    {
        int x;
        current=head;
        while((x!=current->book.booknum)&&(current->next!=NULL))
        {
            front=current;
            current=current->next;
        }
        if(x==current->book.booknum)
        {
            if(current==head)
                head=current->next;
            else
                front->next=current->next;
            free(current);
            PF("删除图书信息成功!\n");
        }
        else
            PF("\n Not found.");
    }
    return head;
}


         
int  del(struct node *book)//删除信息
{
    int h;
    system("cls");
    PF("~~~~~~~~~~~~~~~~图书信息删除~~~~~~~~~~~~~~~\n");
    PF("|1.图书的书号|\n");
    PF("|2.图书的书名|\n");
    PF("请输入序号选择删除方式:");
    SF("%d",&h);
    switch(h)
    {
    case 1:    delsh(book);break;//按书号删除
    case 2:    delsm(book);break;//按书名删除
    default:   PF("输入有误,请重新输入!\n");break;
    }
}


 void insert(NODE *head,struct books book)//插入信息
 {
     
     NODE *new,*front,*current;
     new=(NODE*)malloc(LEN);
     front=(NODE*)malloc(LEN);
     current=(NODE*)malloc(LEN);
     PF("请输入你想要插入的书籍信息(书号、书名、出版社、价格、作者名):");
     SF("%d\t%s\t%s\t%d\t%s\n",new->book.booknum,new->book.bookname,new->book.publish,new-> book.price,new->book.authorname);
     current=head;
     while((current!=NULL)&&((current->book.price)<(new->book.price)))
     {
         front=current;
         current=current->next;
     }
     new->book.booknum=book.booknum;
     new->book.price=book.price;
     strcpy(new->book.publish,book.publish);
     strcpy(new->book.bookname,book.bookname);
     strcpy(new->book.authorname,book.authorname);
     new->next=current;
     if(current==head)
         head=new;
     else
         front->next=new;

 }   
 

void main(struct books book)
{
    int choice,n=0;
    NODE *head;
    head=(NODE*)malloc(LEN);
    head->next=NULL;
    do
    {
        PF("\t\t*****************图书信息管理系统*****************\n");
        PF("\t\t*\t\t|1.图书信息录入                  *\n");
        PF("\t\t*\t\t|2.图书信息查询                  *\n");
        PF("\t\t*\t\t|3.图书信息的删除                *\n");
        PF("\t\t*\t\t|4.图书信息的插入                *\n");
        PF("\t\t*\t\t|5.退出系统                      *\n");
        PF("\t\t*****************图书信息管理系统*****************\n\n\n");
        PF("\t\t请输入以上序号进行选择:\n");
        SF("%d",&choice);
        switch(choice)
        {
          case 1:  luru(head);break;//录入
          case 2:  search(head);break; //查询
          case 3:  del(head);break;//删除
          case 4:  insert(head,book);break;//插入
          case 5:  exit(0);
          default :PF("输入有误,请重新输入!\n");break;
        }
        getchar();
    }
    while(1);

}

虽然整个程序没有语法错误,
但是search(),del(),insert()函数内部有什么问题,为什么执行不起来?

     
搜索更多相关主题的帖子: head next include 出版社 price 
2012-12-30 10:45
G梦
Rank: 1
等 级:新手上路
帖 子:48
专家分:7
注 册:2012-12-27
得分:0 
有木有人啊,来个人拿!!!!
求帮忙,求改错
走过路过都要帮过啊啊啊啊啊啊啊啊啊啊按
2012-12-30 11:12
G梦
Rank: 1
等 级:新手上路
帖 子:48
专家分:7
注 册:2012-12-27
得分:0 
不管到底有木有益,那个宏定义最起码省了好多重复劳动的时间与精力吧
2013-01-01 18:32
G梦
Rank: 1
等 级:新手上路
帖 子:48
专家分:7
注 册:2012-12-27
得分:0 
  真没人看了啊。。。。那个代码分段看就行了啊啊啊啊啊啊啊啊
2013-01-02 18:45



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




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

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