求高手!!
#include
#include
#include
#include
求高手!!
#include
#include
#include
#include
struct books_list
{
char author[20]; /*作者名*/
char bookname[20]; /*书名*/
char publisher[20]; /*出版单位*/
char pbtime[15]; /*出版时间*/
char loginnum[10]; /*登陆号*/
float price; /*价格*/
char classfy[10]; /*分类号*/
struct books_list * next; /*链表的指针域*/
};
struct books_list * Create_Books_Doc(); /*新建链表*/
void InsertDoc(struct books_list * head); /*插入*/
void DeleteDoc(struct books_list * head );/*删除*/
void Print_Book_Doc(struct books_list * head);/*浏览*/
void search_book(struct books_list * head); /*查询*/
void info_change(struct books_list * head);/*修改*/
void save(struct books_list * head);/*保存数据至文件*/
/*新建链表头节点*/
struct books_list * Create_Books_Doc()
{
struct books_list * head;
head=(struct books_list *)malloc(sizeof(struct books_list)); /*分配头节点空间*/
head->next=NULL; /*头节点指针域初始化,定为空*/
return head;
}
/*保存数据至文件*/
void save(struct books_list * head)
{
struct books_list *p;
FILE *fp;
p=head;
fp=fopen("data.txt","w+"); /*以写方式新建并打开 data.txt文件*/
fprintf(fp,"...............................................................................\n"); /*向文件输出表格*/
fprintf(fp," CAS RN book name author dan wei data sortnum price \n");
getch();
/*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/
while(p->next!= NULL)
{
p=p->next;
fprintf(fp,"%-6.6s %-10.10s %-10.10s %-10.10s %-12.12s %-6.6s %.2f \n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price);
}
fclose(fp);
printf(" save data.txt 文件\n");
}
/*插入*/
void InsertDoc(struct books_list *head)
{
/*定义结构体指针变量 s指向开辟的新结点首地址 p为中间变量*/
struct books_list *s, *p;
char flag='Y'; /*定义flag,方便用户选择重复输入*/
p=head;
/*遍历到尾结点,p指向尾结点*/
while(p->next!= NULL)
{
p=p->next;
}
/*开辟新空间,存入数据,添加进链表*/
while(flag=='Y'||flag=='y')
{
s=(struct books_list *)malloc(sizeof(struct books_list));
printf("\n Please input books landed number:");
fflush(stdin);
scanf("%s",s->loginnum);
printf("\n Please enter the book name:");
fflush(stdin);
scanf("%s",s->bookname);
printf("\n Please input book author's name:");
fflush(stdin);
scanf("%s",s->author);
printf("\n Please input book publishing house:");
fflush(stdin);
scanf("%s",s->publisher);
printf("\n Please enter publishing time:");
fflush(stdin);
scanf("%s",s->pbtime);
printf("\n Please input book classification number:");
fflush(stdin);
scanf("%s",s->classfy);
printf("\n Please input book prices:");
fflush(stdin);
scanf("%f",&s->price);
printf("\n");
getch();
p->next=s; /*将新增加的节点添加进链表*/
p=s; /*p指向尾节点,向后移*/
s->next=NULL;
getch();
printf("......Add success!");
getch();
printf("\n Continue to add?(Y/N):");
展开
全部
本文介绍了一个简单的图书管理系统的实现,该系统使用链表来存储图书信息,并提供了创建、插入、删除、浏览、查询和修改图书记录的功能。此外,还实现了将数据保存到文件的功能。
1991

被折叠的 条评论
为什么被折叠?



