求大佬指点图书管理系统(c语言实现)的BUG

博主遇到一个图书管理系统的问题,使用C语言编写。当程序关闭后再重新打开,之前输入的数据丢失,寻求解决方案。
摘要由CSDN通过智能技术生成

为什么程序关闭后在打开没有之前输入的数据

求大佬给个解决办法


#include<stdio.h>

#include<stdlib.h>
#include<string.h>
#include<windows.h>
#include<conio.h> /*清屏、getch()函数*/   


int k=0; /*定义全局变量k*/


typedef struct{   
unsigned int  nums; /*编号*/
int  editor[20]; /*主编*/  
char press[20]; /*出版社*/ 
int  year; /*出版年*/
int  edition; /*版次*/ 
unsigned long long  ISBN; /*ISBN书号*/
    char name[20];  /*书名*/  
    float  price; /*定价*/ 
    unsigned int  have_numbers;    /*拥有本数*/  
    unsigned int  borrowed_numbers; /*借出本数*/
    unsigned int  left_numbers; /*现余本数*/
}BookSystem;


void Pos(int x,int y)/*设置光标位置*/
{
 COORD pos;
 HANDLE hOutput;
 pos.X=x;
 pos.Y=y;
 hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
 SetConsoleCursorPosition(hOutput,pos);
}


int read_file(BookSystem book[]){ /*文件指针*/
FILE *fp;
int i=0;
fp=fopen("book.txt","rb"); 
if(fp == NULL){
printf("\n\n—————库存文件不存在!请创建");
return 0;
}
while(feof(fp)!=1){
fread(&book[i],sizeof(BookSystem),1,fp);
if(book[i].nums==0)
break;
else
i++;
}
fclose(fp);
return i;
}




void save_file(BookSystem book[],int sum){ /*保存图书信息*/
FILE*fp;  
int i;  
if((fp=fopen("book.txt","wb"))==NULL){
printf("写文件错误!\n");  
return;  
}  
for(i=0;i<sum;i++)  
if(fwrite(&book[i],sizeof(BookSystem),1,fp)!=1)  
printf("写文件错误!\n");  
fclose(fp);
}




int input(BookSystem book[]){ /*创建图书信息*/
int i,x;
for(i=0;i<1000;i++){
system("cls"); /*"stdlib.h下函数,清屏"*/
printf("\n\n                 录入图书信息  (最多1000本)\n");
    printf("               ----------------------------\n");  
     
        printf("\n                     第%d本图书",k+1); 
printf("\n 请输入图书的编号 : ");  
        scanf("%d",&book[i].nums);
        printf("\n 请输入图书的主编 : ");  
        scanf("%s",book[i].editor);  
        printf("\n 请输入图书的出版社 : ");  
        scanf("%s",book[i].press);
        printf("\n 请输入图书的出版年 : ");  
        scanf("%d",&book[i].year);
        printf("\n 请输入图书的版次 : ");  
        scanf("%d",&book[i].edition);
        printf("\n 请输入图书的ISBN : ");  
        scanf("%lld",&book[i].ISBN
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值