| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 547 人关注过本帖
标题:各位前辈,看小弟的程序哪错了
只看楼主 加入收藏
谪仙再世
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-5-8
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
各位前辈,看小弟的程序哪错了
程序要求:开发一个图书信息管理系统,图书信息包括:图书编号、书名、作者、出版社、类别、出版时间、价格等基本信息(也可以根据自己情况进行扩充,比如是否借出、库存量等)。使之能提供以下基本功能:
(1)图书信息录入功能(图书信息用文件保存)--输入
(2)图书信息浏览功能--输出
(3)查询功能(至少一种查询方式)、排序功能(至少一种排序方式):
 ①按书名查询 ②按作者名查询  ③ 按照价钱排序 ④按出版时间排序等等
(4)图书信息的删除与修改
扩展功能:可以按照自己的程度进行扩展。比如(1)简单的权限处理 (2)报表打印功能(3)甚至根据自己情况,可以加上学生信息,并扩充为图书借阅系统。(4)模糊查询 (5)综合查询 (6)统计功能  比如统计处某一类别的图书信息  或 筛选出小于指定数量库存的图书信息等等,总之,可以根据自己需求进行分析功能。
程序如下
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 15                                //编号号位数
#define  M 15                                //书名名字节数
#define  L 15                                //作者名字节数
#define  K 15                                //出版社名字节数
#define  J 15                                //类别名字节数
#define  I 15

void printf_(struct book *);                     
void printf_(struct book *);                     
struct book * scanf1_();                        
struct book * scanf_();                        
void print_(struct book *);                    
struct book *num_paixu(struct book *);        
struct book *price_paixu(struct book *);
struct book *time_paixu(struct book *);
void chaxun1(struct book *);                    
void chaxun2(struct book *);
struct book * charu(struct book *);            
struct book * shanchu(struct book *);            
void xiugai(struct book *);                    
void fprint_(struct book *);                    

struct book
{
    char num[N];
    char name[M];
    char writer[L];
    char press[K];
    char kind[J];
    int time;
    float price;
    struct book *next;
};


void main()
{   
    int n,x=1,k=0;
    struct book *head=NULL;

    char ch;
    while(x)
    {    system("cls");
        printf("*******************************************************************************\n");
        printf("                  0---退出系统                    1---录入数据                 \n");
        printf("                  2---保存文件                    3---按照价钱排序              \n");
        printf("                  4---输出信息                    5---按出版时间排序             \n");
        printf("                  6---按书名查询信息              7---按作者名查询信息查询信息                 \n");
        printf("                  8---插入数据                    9---删除数据                 \n");
        printf("                 10---修改数据                   11---读取数据                 \n");
        printf("*******************************************************************************\n");
        scanf("%d",&n);
        getchar();
        switch(n)
        {
            case 0:
                x=0;break;
            case 1:
                head=scanf_();break;
            case 2:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");

                    getchar();
                    break;
                }
                else
                    fprint_(head);break;
            case 3:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                {
                    head=price_paixu(head);
                    break;
                }
            case 4:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                    print_(head);break;
            case 5:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                {
                    head=time_paixu(head);
                    printf("是否显示排序结果 Y/N ?");
                    ch=getchar();getchar();
                    if(ch=='y'||ch=='Y')
                    {
                        printf("\n");
                        print_(head);
                    }
                    break;
                }
            case 6:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                {
                    chaxun1(head);
                    getchar();
                    break;
                }
            
            case 7:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                {
                    chaxun2(head);
                    getchar();
                    break;
                }
        
            case 8:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                    head=charu(head);break;
            
            case 9:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                {
                    head=shanchu(head);
                    break;
                }
        
            case 10:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                {
                    xiugai(head);
                    break;
                }
/*            case 11:
                head = load();
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书的数据!");
                    getchar();
                }
                break;
                */
               
               
               
               

               
            
            default :
                printf("输入有误,请重新输入!");
                getchar();
                break;
        }
    }
}


void printf_(struct book *p0)
{
    int i;
    printf("图书编号:");
    puts(p0->num);
    printf("书名:");
    puts(p0->name);
    printf("作者:");
    puts(p0->writer);
    printf("出版社:");
    puts(p0->press);
    printf("类别:");
    puts(p0->kind);
    printf("出版时间:");
    puts(p0->time);
    printf("价格:");
    puts(p0->price);
    printf("\n");
}

struct book * scanf1_()
{
    int i,sum=0;
    struct book *p0;
    p0=(struct book *)malloc(sizeof(struct book));
    printf("请输入图书编号:");
    gets(p0->num);
    printf("请输入书名:");
    gets(p0->name);
    printf("请输入作者:");
    gets(p0->writer);
    printf("请输入出版社:");
    gets(p0->press);
    printf("请输入类别:");
    gets(p0->kind);
    printf("请输入出版时间:");
    gets(p0->time);
    printf("请输入价格:");
    gets(p0->price);
    return p0;
}

struct book * scanf_()
{
    struct book *p1,*p2,*head;   
    int i,sum=0,n=0;
    printf("注意:当图书编号为  0  时输入结束\n\n");
    p1=(struct book *)malloc(sizeof(struct book));   /*得到学生信息*/
    head=p2=p1;
    do
    {    printf("请输入图书编号:");   
        gets(p1->num);
        if(strcmp(p1->num,"0")==0)
            break;
        printf("请输入书名:");
        gets(p1->name);
        printf("请输入作者:");
        gets(p1->writer);
        printf("请输入出版社:");
        gets(p1->press);
        printf("请输入类别:");
        gets(p1->kind);
        printf("请输入出版时间:");
        gets(p1->time);
        printf("请输入价格:");
        gets(p1->price);
        p1=(struct book *)malloc(sizeof(struct book));
        p2->next=p1;
        p2=p1;
        n++;
    }while(1);
    p1->next=NULL;
    printf("图书数据输入结束!\n");   
    getchar();/*图书的数据被放在链表中*/
    return head;
}
   
void print_(struct book *head)            
{
    int i;
    struct book *p1,*p2;
    p1=p2=head;
    while(p1->next!=NULL)
    {
        printf("编号: ");
        puts(p1->num);
        printf("书名: ");
        puts(p1->name);
        printf("作者:");
        puts(p1->writer);
        printf("出版社:");
        puts(p1->press);
        printf("类别:");
        puts(p1->kind);
        printf("时间:");
        puts(p1->time);
        printf("价格:");
        puts(p1->price);
        printf("\n");
        p1=p2->next;
        p2=p1;
    }
    getchar();
}
   
struct book *num_paixu(struct book *head)               
{
    struct book *p1,*p2,*p3,*p4,*p5,*p6,*p7;
    int x=1;
    for(p1=head;p1->next!=NULL;p4=p1,p1=p1->next)
    {
        p3=p1;
        for(p2=p1->next,p5=p7=p2;p2->next!=NULL;p7=p2,p2=p2->next)
        {
            if(strcmp(p3->num,p2->num)>0)
            {
                p3=p2;
                p5=p7;
            }
        }
        if(p3!=p1)
        {            
            if(x&&p1==head)
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p5->next=p1;
                head=p3;
                p1=p3;
                x=0;
            }
            else
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p4->next=p3;
                p5->next=p1;
                p1=p3;
            }

        }
    }
    printf("排序成功!\n");
    return head;
}

void chaxun1(struct book *head)
{
    char a[M];
    struct book *p1;
    printf("请输入要查询的书名:");
    gets(a);
    p1=head;
    while(p1->next!=NULL)
    {
        if(strcmp(p1->name,a)==0)
            break;
        p1=p1->next;
    }
    if(p1->next==NULL)
        printf("没有找到书名为 %s 的图书!\n",a);
    else
    {
        printf("要查询的图书信息如下:\n\n");
        printf_(p1);
    }
void chaxun2(struct book *head)
{
    char a[L];
    struct book *p1;
    printf("请输入要查询的作者名:");
    gets(a);
    p1=head;
    while(p1->next!=NULL)
    {
        if(strcmp(p1->writer,a)==0)
            break;
        p1=p1->next;
    }
    if(p1->next==NULL)
        printf("没有找到作者名为 %s 的图书!\n",a);
    else
    {
        printf("要查询的图书信息如下:\n\n");
        printf_(p1);
    }

}

struct book * charu(struct book *head)
{
    struct book *p1,*p2,*p3;
    p1=scanf1_();
    p2=head;
    p3=p2;
    while((strcmp(p2->num,p1->num)<0)&&p2->next!=NULL)
    {
        p3=p2;
        p2=p2->next;
    }
    if(p2==head)
    {
        p1->next=head;
        head=p1;
    }
    else
    {
        p3->next=p1;
        p1->next=p2;
    }
    printf("插入成功!\n");
    getchar();
    return head;
}
//删除数据
struct book * shanchu(struct book *head)
{
    char a[N];
    struct book *p1,*p2,*p3;
    printf("请输入要删除的图书的编号:");
    gets(a);
    p1=head;
    p2=p1;
    while((strcmp(p2->num,a)!=0)&&p2->next!=NULL)
    {
        p3=p2;
        p2=p2->next;
    }
    if(p2->next==NULL)
        printf("没有找到要删除的数据!\n");
    else if(p2==head)
    {
        head=p2->next;
        printf("删除成功!\n");
    }
    else
    {   
        p3->next=p2->next;
        printf("删除成功!\n");
    }
    getchar();
    return head;
}

void xiugai(struct book *head)
{
    char a[N];
    struct book *p1;
    int i,k;
    printf("输入要修改的图书的编号");
    gets(a);
    p1=head;
    while(p1->next!=NULL)
    {
        if(strcmp(p1->num,a)==0)
            break;
        p1=p1->next;
    }
    if(p1->next==NULL)
    {
        printf("没有要找的学生信息!\n");
        getchar();
    }
    else
    {
        printf("***********************************\n");
        printf("*    0---放弃修改                 *\n");
        printf("*    1---修改编号                 *\n");
        printf("*    2---修改书名                 *\n");
        printf("*    3---修改作者                 *\n");
        printf("*    4---修改出版社               *\n");
        printf("*    5---修改类别                 *\n");
        printf("*    6---修改出版时间             *\n");
        printf("*    7---修改价格                 *\n");
        printf("*    8---修改全部                 *\n");
        printf("***********************************\n");
        scanf("%d",&k);
        getchar();
        switch(k)
        {
            case 0:
                break;
            case 1:
                printf("请输入新编号:");
                gets(p1->num);
                printf("修改成功!");
                getchar();
                break;
            case 2:
                printf("请输入新书名:");
                gets(p1->name);
                printf("修改成功!");
                getchar();
                break;
            case 3:
                printf("请输入新作者名:");
                gets(p1->writer);
                printf("修改成功!");
                getchar();
                break;
            case 4:
                printf("请输入新出版社名:");
                gets(p1->press);
                printf("修改成功!");
                getchar();
                break;
            case 5:
                printf("请输入新类别名:");
                gets(p1->kind);
                printf("修改成功!");
                getchar();
                break;

            case 6:
                printf("请输入新出版时间:");
                gets(p1->time);
                printf("修改成功!");
                getchar();
                break;
            case 7:
                printf("请输入新价格:");
                gets(p1->price);
                printf("修改成功!");
                getchar();
                break;
            case 8:
                printf("请输入新的编号:");
                gets(p1->num);
                printf("请输入新的书名:");
                gets(p1->name);
                printf("请输入新的作者名:");
                gets(p1->writer);
                printf("请输入新的出版社名:");
                gets(p1->press);
                printf("请输入新的类别名:");
                gets(p1->kind);
                printf("请输入新的出版时间:");
                gets(p1->time);
                printf("请输入新的价格:");
                gets(p1->price);
                getchar();
                break;
            default:
                printf("您的输入有误!");
                getchar();
                break;
        }
    }
}
//把数据写入到文件
void fprint_(struct book *head)
{
    FILE *fb;
    struct book *p1;   
    if((fb=fopen("图书信息.txt","w"))==NULL)
    {
        printf("文件   图书信息.txt    打开失败");
        exit(0);
    }
    fprintf(fb,"编号          书名         作者          出版社         类别         出版时间         价格\n");
    for(p1=head;p1->next!=NULL;p1=p1->next)
        fprintf(fb,"%-13%s-15%s-15%s-15%s-15%s-15%d-%f\n",p1->num,p1->name,p1->writer,p1->press,p1->kind,p1->time,p1->price);
    fclose(fb);        
    printf("文件成功保存到  图书信息.txt 中!\n");
    getchar();
}


struct book *price_paixu(struct book *head)               
{
    struct book *p1,*p2,*p3,*p4,*p5,*p6,*p7;
    int x=1;
    for(p1=head;p1->next!=NULL;p4=p1,p1=p1->next)
    {
        p3=p1;
        for(p2=p1->next,p5=p7=p2;p2->next!=NULL;p7=p2,p2=p2->next)
        {
            if(strcmp(p3->num,p2->num)>0)
            {
                p3=p2;
                p5=p7;
            }
        }
        if(p3!=p1)
        {            
            if(x&&p1==head)
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p5->next=p1;
                head=p3;
                p1=p3;
                x=0;
            }
            else
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p4->next=p3;
                p5->next=p1;
                p1=p3;
            }

        }
    }
    printf("排序成功!\n");
    return head;
}
struct book *time_paixu(struct book *head)               
{
    struct book *p1,*p2,*p3,*p4,*p5,*p6,*p7;
    int x=1;
    for(p1=head;p1->next!=NULL;p4=p1,p1=p1->next)
    {
        p3=p1;
        for(p2=p1->next,p5=p7=p2;p2->next!=NULL;p7=p2,p2=p2->next)
        {
            if(strcmp(p3->num,p2->num)>0)
            {
                p3=p2;
                p5=p7;
            }
        }
        if(p3!=p1)
        {            
            if(x&&p1==head)
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p5->next=p1;
                head=p3;
                p1=p3;
                x=0;
            }
            else
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p4->next=p3;
                p5->next=p1;
                p1=p3;
            }

        }
    }
    printf("排序成功!\n");
    return head;
}
搜索更多相关主题的帖子: 时间 出版社 
2011-05-08 13:38
谪仙再世
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-5-8
收藏
得分:0 
,没人吗?
2011-05-08 13:40
谪仙再世
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-5-8
收藏
得分:0 
E:\文档\c源代码\3.c(216) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
E:\文档\c源代码\3.c(216) : warning C4024: 'puts' : different types for formal and actual parameter 1
E:\文档\c源代码\3.c(218) : error C2115: 'function' : incompatible types
E:\文档\c源代码\3.c(218) : warning C4024: 'puts' : different types for formal and actual parameter 1
E:\文档\c源代码\3.c(238) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
E:\文档\c源代码\3.c(238) : warning C4024: 'gets' : different types for formal and actual parameter 1
E:\文档\c源代码\3.c(240) : error C2115: 'function' : incompatible types
E:\文档\c源代码\3.c(240) : warning C4024: 'gets' : different types for formal and actual parameter 1
E:\文档\c源代码\3.c(265) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
E:\文档\c源代码\3.c(265) : warning C4024: 'gets' : different types for formal and actual parameter 1
E:\文档\c源代码\3.c(267) : error C2115: 'function' : incompatible types
E:\文档\c源代码\3.c(267) : warning C4024: 'gets' : different types for formal and actual parameter 1
E:\文档\c源代码\3.c(297) : warning C4047: 'function' : 'const char *' differs in levels of indirection from 'int '
E:\文档\c源代码\3.c(297) : warning C4024: 'puts' : different types for formal and actual parameter 1
E:\文档\c源代码\3.c(299) : error C2115: 'function' : incompatible types
E:\文档\c源代码\3.c(299) : warning C4024: 'puts' : different types for formal and actual parameter 1
E:\文档\c源代码\3.c(370) : error C2143: syntax error : missing ';' before 'type'
E:\文档\c源代码\3.c(373) : error C2143: syntax error : missing ';' before 'type'
E:\文档\c源代码\3.c(519) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
E:\文档\c源代码\3.c(519) : warning C4024: 'gets' : different types for formal and actual parameter 1
E:\文档\c源代码\3.c(525) : error C2115: 'function' : incompatible types
E:\文档\c源代码\3.c(525) : warning C4024: 'gets' : different types for formal and actual parameter 1
E:\文档\c源代码\3.c(541) : warning C4047: 'function' : 'char *' differs in levels of indirection from 'int '
E:\文档\c源代码\3.c(541) : warning C4024: 'gets' : different types for formal and actual parameter 1
E:\文档\c源代码\3.c(543) : error C2115: 'function' : incompatible types
E:\文档\c源代码\3.c(543) : warning C4024: 'gets' : different types for formal and actual parameter 1
E:\文档\c源代码\3.c(565) : error C2018: unknown character '0xa3'
E:\文档\c源代码\3.c(565) : error C2018: unknown character '0xac'
E:\文档\c源代码\3.c(565) : error C2146: syntax error : missing ')' before identifier 'p1'
E:\文档\c源代码\3.c(565) : error C2059: syntax error : ')'
错误信息,表示不懂,这是本学期最终作业很重要,感激不尽
2011-05-08 13:52
fangdong65
Rank: 5Rank: 5
等 级:职业侠客
帖 子:73
专家分:301
注 册:2011-4-1
收藏
得分:20 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 15                                //编号号位数
#define  M 15                                //书名名字节数
#define  L 15                                //作者名字节数
#define  K 15                                //出版社名字节数
#define  J 15                                //类别名字节数
#define  I 15

void printf_(struct book *);                     
void printf_(struct book *);                     
struct book * scanf1_();                        
struct book * scanf_();                        
void print_(struct book *);                    
struct book *num_paixu(struct book *);        
struct book *price_paixu(struct book *);
struct book *time_paixu(struct book *);
void chaxun1(struct book *);                    
void chaxun2(struct book *);
struct book * charu(struct book *);            
struct book * shanchu(struct book *);            
void xiugai(struct book *);                    
void fprint_(struct book *);                    

struct book
{
    char num[N];
    char name[M];
    char writer[L];
    char press[K];
    char kind[J];
    int time;
    float price;
    struct book *next;
};


void main()
{   
    int n,x=1,k=0;
    struct book *head=NULL;

    char ch;
    while(x)
    {    system("cls");
        printf("*******************************************************************************\n");
        printf("                  0---退出系统                    1---录入数据                 \n");
        printf("                  2---保存文件                    3---按照价钱排序              \n");
        printf("                  4---输出信息                    5---按出版时间排序             \n");
        printf("                  6---按书名查询信息              7---按作者名查询信息查询信息                 \n");
        printf("                  8---插入数据                    9---删除数据                 \n");
        printf("                 10---修改数据                   11---读取数据                 \n");
        printf("*******************************************************************************\n");
        scanf("%d",&n);
        getchar();
        switch(n)
        {
            case 0:
                x=0;break;
            case 1:
                head=scanf_();break;
            case 2:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");

                    getchar();
                    break;
                }
                else
                    fprint_(head);break;
            case 3:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                {
                    head=price_paixu(head);
                    break;
                }
            case 4:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                    print_(head);break;
            case 5:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                {
                    head=time_paixu(head);
                    printf("是否显示排序结果 Y/N ?");
                    ch=getchar();getchar();
                    if(ch=='y'||ch=='Y')
                    {
                        printf("\n");
                        print_(head);
                    }
                    break;
                }
            case 6:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                {
                    chaxun1(head);
                    getchar();
                    break;
                }
            
            case 7:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                {
                    chaxun2(head);
                    getchar();
                    break;
                }
        
            case 8:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                    head=charu(head);break;
            
            case 9:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                {
                    head=shanchu(head);
                    break;
                }
        
            case 10:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书数据!");
                    getchar();
                    break;
                }
                else
                {
                    xiugai(head);
                    break;
                }
/*            case 11:
                head = load();
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入图书的数据!");
                    getchar();
                }
                break;
                */
               
               
               
               

               
            
            default :
                printf("输入有误,请重新输入!");
                getchar();
                break;
        }
    }
}


void printf_(struct book *p0)
{
    //int i;没有引用不需要定义该变量,下同,否则会有警告
    printf("图书编号:");
    puts(p0->num);
    printf("书名:");
    puts(p0->name);
    printf("作者:");
    puts(p0->writer);
    printf("出版社:");
    puts(p0->press);
    printf("类别:");
    puts(p0->kind);
    printf("出版时间:");
    //puts(p0->time);//puts函数只用于输出字符串,不能用于输出字符和数值,下同
    printf("%d\n",p0->time);
    printf("价格:");
    //puts(p0->price);
    printf("%d\n",p0->price);
    printf("\n");
}

struct book * scanf1_()
{
    int i,sum=0;//i没用不需要定义,否则有警告
    struct book *p0;
    p0=(struct book *)malloc(sizeof(struct book));
    printf("请输入图书编号:");
    gets(p0->num);
    printf("请输入书名:");
    gets(p0->name);
    printf("请输入作者:");
    gets(p0->writer);
    printf("请输入出版社:");
    gets(p0->press);
    printf("请输入类别:");
    gets(p0->kind);
    printf("请输入出版时间:");
    //gets(p0->time);//gets()函数和puts()函数相对,用法相同
    scanf("%d",&p0->time);
    printf("请输入价格:");
    //gets(p0->price);
    scanf("%d",&p0->price);
    return p0;
}

struct book * scanf_()
{
    struct book *p1,*p2,*head;   
    int i,sum=0,n=0;
    printf("注意:当图书编号为  0  时输入结束\n\n");
    p1=(struct book *)malloc(sizeof(struct book));   /*得到学生信息*/
    head=p2=p1;
    do
    {    printf("请输入图书编号:");   
        gets(p1->num);
        if(strcmp(p1->num,"0")==0)
            break;
        printf("请输入书名:");
        gets(p1->name);
        printf("请输入作者:");
        gets(p1->writer);
        printf("请输入出版社:");
        gets(p1->press);
        printf("请输入类别:");
        gets(p1->kind);
        printf("请输入出版时间:");
        gets(p1->time);

        printf("请输入价格:");
        gets(p1->price);
        p1=(struct book *)malloc(sizeof(struct book));
        p2->next=p1;
        p2=p1;
        n++;
    }while(1);
    p1->next=NULL;
    printf("图书数据输入结束!\n");   
    getchar();/*图书的数据被放在链表中*/
    return head;
}
   
void print_(struct book *head)            
{
    int i;
    struct book *p1,*p2;
    p1=p2=head;
    while(p1->next!=NULL)
    {
        printf("编号: ");
        puts(p1->num);
        printf("书名: ");
        puts(p1->name);
        printf("作者:");
        puts(p1->writer);
        printf("出版社:");
        puts(p1->press);
        printf("类别:");
        puts(p1->kind);
        printf("时间:");
        puts(p1->time);
        printf("价格:");
        puts(p1->price);
        printf("\n");
        p1=p2->next;
        p2=p1;
    }
    getchar();
}
   
struct book *num_paixu(struct book *head)               
{
    struct book *p1,*p2,*p3,*p4,*p5,*p6,*p7;
    int x=1;
    for(p1=head;p1->next!=NULL;p4=p1,p1=p1->next)
    {
        p3=p1;
        for(p2=p1->next,p5=p7=p2;p2->next!=NULL;p7=p2,p2=p2->next)
        {
            if(strcmp(p3->num,p2->num)>0)
            {
                p3=p2;
                p5=p7;
            }
        }
        if(p3!=p1)
        {            
            if(x&&p1==head)
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p5->next=p1;
                head=p3;
                p1=p3;
                x=0;
            }
            else
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p4->next=p3;
                p5->next=p1;
                p1=p3;
            }

        }
    }
    printf("排序成功!\n");
    return head;
}

void chaxun1(struct book *head)
{
    char a[M];
    struct book *p1;
    printf("请输入要查询的书名:");
    gets(a);
    p1=head;
    while(p1->next!=NULL)
    {
        if(strcmp(p1->name,a)==0)
            break;
        p1=p1->next;
    }
    if(p1->next==NULL)
        printf("没有找到书名为 %s 的图书!\n",a);
    else
    {
        printf("要查询的图书信息如下:\n\n");
        printf_(p1);
    }
}//少了一个}
void chaxun2(struct book *head)
{
    char a[L];
    struct book *p1;
    printf("请输入要查询的作者名:");
    gets(a);
    p1=head;
    while(p1->next!=NULL)
    {
        if(strcmp(p1->writer,a)==0)
            break;
        p1=p1->next;
    }
    if(p1->next==NULL)
        printf("没有找到作者名为 %s 的图书!\n",a);
    else
    {
        printf("要查询的图书信息如下:\n\n");
        printf_(p1);
    }

}

struct book * charu(struct book *head)
{
    struct book *p1,*p2,*p3;
    p1=scanf1_();
    p2=head;
    p3=p2;
    while((strcmp(p2->num,p1->num)<0)&&p2->next!=NULL)
    {
        p3=p2;
        p2=p2->next;
    }
    if(p2==head)
    {
        p1->next=head;
        head=p1;
    }
    else
    {
        p3->next=p1;
        p1->next=p2;
    }
    printf("插入成功!\n");
    getchar();
    return head;
}
//删除数据
struct book * shanchu(struct book *head)
{
    char a[N];
    struct book *p1,*p2,*p3;
    printf("请输入要删除的图书的编号:");
    gets(a);
    p1=head;
    p2=p1;
    while((strcmp(p2->num,a)!=0)&&p2->next!=NULL)
    {
        p3=p2;
        p2=p2->next;
    }
    if(p2->next==NULL)
        printf("没有找到要删除的数据!\n");
    else if(p2==head)
    {
        head=p2->next;
        printf("删除成功!\n");
    }
    else
    {   
        p3->next=p2->next;
        printf("删除成功!\n");
    }
    getchar();
    return head;
}

void xiugai(struct book *head)
{
    char a[N];
    struct book *p1;
    int i,k;
    printf("输入要修改的图书的编号");
    gets(a);
    p1=head;
    while(p1->next!=NULL)
    {
        if(strcmp(p1->num,a)==0)
            break;
        p1=p1->next;
    }
    if(p1->next==NULL)
    {
        printf("没有要找的学生信息!\n");
        getchar();
    }
    else
    {
        printf("***********************************\n");
        printf("*    0---放弃修改                 *\n");
        printf("*    1---修改编号                 *\n");
        printf("*    2---修改书名                 *\n");
        printf("*    3---修改作者                 *\n");
        printf("*    4---修改出版社               *\n");
        printf("*    5---修改类别                 *\n");
        printf("*    6---修改出版时间             *\n");
        printf("*    7---修改价格                 *\n");
        printf("*    8---修改全部                 *\n");
        printf("***********************************\n");
        scanf("%d",&k);
        getchar();
        switch(k)
        {
            case 0:
                break;
            case 1:
                printf("请输入新编号:");
                gets(p1->num);
                printf("修改成功!");
                getchar();
                break;
            case 2:
                printf("请输入新书名:");
                gets(p1->name);
                printf("修改成功!");
                getchar();
                break;
            case 3:
                printf("请输入新作者名:");
                gets(p1->writer);
                printf("修改成功!");
                getchar();
                break;
            case 4:
                printf("请输入新出版社名:");
                gets(p1->press);
                printf("修改成功!");
                getchar();
                break;
            case 5:
                printf("请输入新类别名:");
                gets(p1->kind);
                printf("修改成功!");
                getchar();
                break;

            case 6:
                printf("请输入新出版时间:");
               gets(p1->time);
                printf("修改成功!");
                getchar();
                break;
            case 7:
                printf("请输入新价格:");
                gets(p1->price);
                printf("修改成功!");
                getchar();
                break;
            case 8:
                printf("请输入新的编号:");
                gets(p1->num);
                printf("请输入新的书名:");
                gets(p1->name);
                printf("请输入新的作者名:");
                gets(p1->writer);
                printf("请输入新的出版社名:");
                gets(p1->press);
                printf("请输入新的类别名:");
                gets(p1->kind);
                printf("请输入新的出版时间:");
                gets(p1->time);
                printf("请输入新的价格:");
                gets(p1->price);
                getchar();
                break;
            default:
                printf("您的输入有误!");
                getchar();
                break;
        }
    }
}
//把数据写入到文件
void fprint_(struct book *head)
{
    FILE *fb;
    struct book *p1;   
    if((fb=fopen("图书信息.txt","w"))==NULL)
    {
        printf("文件   图书信息.txt    打开失败");
        exit(0);
    }
    fprintf(fb,"编号          书名         作者          出版社         类别         出版时间         价格\n");
    for(p1=head;p1->next!=NULL;p1=p1->next)
        //fprintf(fb,"%-13%s-15%s-15%s-15%s-15%s-15%d-%f\n",p1->num,p1->name,p1->writer,p1->press,p1->kind,p1->timep1->price);中文输入法下面输入的符号是错误的
    fprintf(fb,"%-13s%-15s%-15s%-15s%-15s%-15d%-f\n",p1->num,p1->name,p1->writer,p1->press,p1->kind,p1->time,p1->price);
    fclose(fb);        
    printf("文件成功保存到  图书信息.txt 中!\n");
    getchar();
}


struct book *price_paixu(struct book *head)               
{
    struct book *p1,*p2,*p3,*p4,*p5,*p6,*p7;
    int x=1;
    for(p1=head;p1->next!=NULL;p4=p1,p1=p1->next)
    {
        p3=p1;
        for(p2=p1->next,p5=p7=p2;p2->next!=NULL;p7=p2,p2=p2->next)
        {
            if(strcmp(p3->num,p2->num)>0)
            {
                p3=p2;
                p5=p7;
            }
        }
        if(p3!=p1)
        {            
            if(x&&p1==head)
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p5->next=p1;
                head=p3;
                p1=p3;
                x=0;
            }
            else
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p4->next=p3;
                p5->next=p1;
                p1=p3;
            }

        }
    }
    printf("排序成功!\n");
    return head;
}
struct book *time_paixu(struct book *head)               
{
    struct book *p1,*p2,*p3,*p4,*p5,*p6,*p7;
    int x=1;
    for(p1=head;p1->next!=NULL;p4=p1,p1=p1->next)
    {
        p3=p1;
        for(p2=p1->next,p5=p7=p2;p2->next!=NULL;p7=p2,p2=p2->next)
        {
            if(strcmp(p3->num,p2->num)>0)
            {
                p3=p2;
                p5=p7;
            }
        }
        if(p3!=p1)
        {            
            if(x&&p1==head)
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p5->next=p1;
                head=p3;
                p1=p3;
                x=0;
            }
            else
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p4->next=p3;
                p5->next=p1;
                p1=p3;
            }

        }
    }
    printf("排序成功!\n");
    return head;
}
puts()和gets()只能用于字符串,不能用于数值和字符,都是一些小问题,自己慢慢调试都会找到错误的,多动动手。
收到的鲜花
2011-05-08 14:11
谪仙再世
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-5-8
收藏
得分:0 
谢谢了,能运行了,不过还需要修改。
2011-05-08 14:24
快速回复:各位前辈,看小弟的程序哪错了
数据加载中...
 
   



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

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