标题:来大佬帮我看看,我这小的信息管理系统有什么问题,为什么用编译器运行到半 ...
只看楼主
z15602499553
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2017-9-28
结帖率:100%
已结贴  问题点数:20 回复次数:1 
来大佬帮我看看,我这小的信息管理系统有什么问题,为什么用编译器运行到半路,程序就停止工作了
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 5
struct book_type
{
    char name[15];
    char author[15];
    int date;
    int pages;
    float price;
}book[SIZE];
void input();
void searching();
void output();
void save();
void order();

int num;

int main()
{   while(1)
    {  printf("******************************************\n");
       printf("欢迎使用图书数据库系统\n");
       printf("请根据以下提示进行操作\n");
       printf("录入图书信息请输入数字1\n");
       printf("搜索图书请输入数字2\n");
       printf("输出所有图书的信息请输入数字3\n");
       printf("退出系统请输入数字0\n");
       printf("******************************************\n");
        switch(getchar())
        {
               
                case'1': input();    break;
                case'2': searching();break;
                case'3': output();   break;
                case'0': exit(0);
        }
    }
  
     return 0;

}

void input()
{    int i=0,YN=0;
     while(i<SIZE)
     {   printf("******请录入图书的信息******\n");
         printf("书名  作者  出版年份  页数  价格\n");
         scanf("%15s%15s%d%d%f",book[i].name,book[i].author,book[i].date,
               &book[i].date,&book[i].pages,&book[i].price);
         printf("继续录入? \nY(1) N(0)\n");
         scanf("%d",&YN);
         if(YN==0)break;
         i++;
     }
     order();
     save();
     return;
}

void save()
{
    FILE*fp;
    int i;
    fp=fopen("book_list","wb");
    for(i=0;i<SIZE;i++)
    {
        if(fwrite(&book[i],sizeof(struct book_type),1,fp)!=1)
        printf("file write error\n");
    }
    printf("\nfile save\n");
    fclose(fp);
    return;
   
}

void output()
{
    FILE *fp;
    int i;
    fp=fopen("book_list","rb");
    printf("书名   作者   出版年份   页数   价格\n");
    for(i=0;i<SIZE;i++)
    {
        fread(&book[i],sizeof(struct book_type),1,fp);
        printf("%-15s%-15s%-6d%-6d%-6d\n",book[i].name,book[i].author,book[i].date,
               &book[i].date,&book[i].pages,&book[i].price);
    }
    fclose(fp);
    return;
}

void searching()
{
    char nm[15];
    int i,aa;
    FILE*fp;
    fp=fopen("book_list","rb");
    for(i=0;i<SIZE;i++)
    {
       fread(&book[i],sizeof(struct book_type),1,fp);   
    }
    printf("请输入书名\n");
    scanf("%s",nm);
    for(i=0;i<SIZE;i++)
       if(strcmp(nm,book[i].name)==0)
        {   printf("***************************************");
            printf("书名   作者   出版年份   页数   价格\n");
            printf("%-15s%-15s%-6d%-6d%-6d\n",book[i].name,book[i].author,
            &book[i].date,&book[i].pages,&book[i].price);
            printf("***************************************");
            break;
        }
   return;   
}

void order()
{   
    struct book_type chane;
    int i,j;
    for(j=0;j<SIZE;j++)
     for(i=0;i<SIZE-j;i++)
     if(book[i].date>book[i+1].date)
     {  
        
         strcpy(chane.name,book[i].name);strcpy(chane.author,book[i].author);
        chane.date=book[i].date;chane.pages=book[i].pages;
        chane.price=book[i].price;//
        strcpy(book[i].name,book[i+1].name);strcpy(book[i].author,book[i+1].author);
        book[i].date=book[i+1].date;book[i].pages=book[i+1].pages;
        book[i].price=book[i+1].price;//
        strcpy(book[i+1].name,chane.name);strcpy(book[i+1].author,chane.author);
        book[i+1].date=chane.date;book[i+1].pages=chane.pages;
        book[i+1].price=chane.price;//
     }
     return
   
}

搜索更多相关主题的帖子: name date price void printf 
2017-09-28 09:41
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
得分:20 
编译告警一定要清。
程序代码:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 5
struct book_type
{
    char name[15];
    char author[15];
    int date;
    int pages;
    float price;
}book[SIZE];
void input();
void searching();
void output();
void save();
void order();

int num;

int main()
{
    while (1)
    {
        printf("******************************************\n");
        printf("欢迎使用图书数据库系统\n");
        printf("请根据以下提示进行操作\n");
        printf("录入图书信息请输入数字1\n");
        printf("搜索图书请输入数字2\n");
        printf("输出所有图书的信息请输入数字3\n");
        printf("退出系统请输入数字0\n");
        printf("******************************************\n");
        switch (getchar())
        {

        case'1': input();    break;
        case'2': searching(); break;
        case'3': output();   break;
        case'0': exit(0);
        }
    }

    return 0;

}

void input()
{
    int i = 0, YN = 0;
    while (i<SIZE)
    {
        printf("******请录入图书的信息******\n");
        printf("书名  作者  出版年份  页数  价格\n");
        scanf("%15s%15s%d%d%f", book[i].name, book[i].author,
            &book[i].date, &book[i].pages, &book[i].price);
        printf("继续录入? \nY(1) N(0)\n");
        scanf("%d", &YN);
        if (YN == 0)break;
        i++;
    }
    order();
    save();
    return;
}

void save()
{
    FILE*fp;
    int i;
    fp = fopen("book_list", "wb");
    for (i = 0; i<SIZE; i++)
    {
        if (fwrite(&book[i], sizeof(struct book_type), 1, fp) != 1)
            printf("file write error\n");
    }
    printf("\nfile save\n");
    fclose(fp);
    return;

}

void output()
{
    FILE *fp;
    int i;
    fp = fopen("book_list", "rb");
    printf("书名   作者   出版年份   页数   价格\n");
    for (i = 0; i<SIZE; i++)
    {
        fread(&book[i], sizeof(struct book_type), 1, fp);
        printf("%-15s%-15s%-6d%-6d%-6f\n", book[i].name, book[i].author, book[i].date,
             book[i].pages, book[i].price);
    }
    fclose(fp);
    return;
}

void searching()
{
    char nm[15];
    int i, aa;
    FILE*fp;
    fp = fopen("book_list", "rb");
    for (i = 0; i<SIZE; i++)
    {
        fread(&book[i], sizeof(struct book_type), 1, fp);
    }
    printf("请输入书名\n");
    scanf("%s", nm);
    for (i = 0; i<SIZE; i++)
        if (strcmp(nm, book[i].name) == 0)
        {
            printf("***************************************");
            printf("书名   作者   出版年份   页数   价格\n");
            printf("%-15s%-15s%-6d%-6d%-6f\n", book[i].name, book[i].author,
                book[i].date, book[i].pages, book[i].price);
            printf("***************************************");
            break;
        }
    return;
}

void order()
{
    struct book_type chane;
    int i, j;
    for (j = 0; j<SIZE-1; j++)
        for (i = 0; i<SIZE-1 - j; i++)
            if (book[i].date>book[i + 1].date)
            {

                strcpy(chane.name, book[i].name); strcpy(chane.author, book[i].author);
                chane.date = book[i].date; chane.pages = book[i].pages;
                chane.price = book[i].price;//
                strcpy(book[i].name, book[i + 1].name); strcpy(book[i].author, book[i + 1].author);
                book[i].date = book[i + 1].date; book[i].pages = book[i + 1].pages;
                book[i].price = book[i + 1].price;//
                strcpy(book[i + 1].name, chane.name); strcpy(book[i + 1].author, chane.author);
                book[i + 1].date = chane.date; book[i + 1].pages = chane.pages;
                book[i + 1].price = chane.price;//
            }
    return;

}
2017-09-28 12:04



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




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

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