基于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);
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);
head=head->next;
}
printf