图书管理系统

基于C的图书管理系统

  • c 指针
  • c 单向链表
  • 结构体指针
  • 提供基本的录入、查询、显示、删除功能接口
  • 基于对指针、数组和文件的操作,实时同步
//学生成绩管理系统
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include <string.h>
#define FL "D:/book.txt"
//链表的定义
struct library
{
   
    int book_id;            //图书编号
    char book_name[20];        //书名
    char name[20];            //作者姓名
    char press[20];            //出版社
    struct library *next;
};

//录入图书的信息
int create()
{
   
 int length;        //链表的长度
 struct library *head;
    FILE *fp;
    struct library *p1,*p2;
    length=0;
    p1=p2=(struct library *)malloc(sizeof(struct library));
 printf("请输入图书编号:\n");
    scanf("%d",&p1->book_id);
 head=NULL;
 do
 {
   
 printf("请输入图书的书名\t作者姓名\t出版社\n");
 scanf("%s %s %s",p1->book_name,p1->name,p1->press);
 length++;
 if(length==1) head=p1;
 else p2->next=p1;
 p2=p1;
 p1=(struct library *)malloc(sizeof(struct library));
 printf("请输入图书编号:\n");
 scanf("%d",&p1->book_id);
 }while(p1->book_id!=0);
 //free(p1);
 p2->next=NULL;
if((fp=fopen(FL,"wb"))==NULL)
    {
   
       printf("无法打开该文件夹\n");
       exit(0);
    }
    while(head)
      {
   
    fprintf(fp,"%d %s %s %s\n",head->book_id,head->book_name,head->name,head->press);//向 fp 所指向的文件写入数据(输出)。
    //fwrite(head,sizeof(struct library),1,fp);
       head=head->next;
       }
 printf
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值