c语言exe自动退出,C语言程序自动跳出问题急!!!!!求解求高手!!#include 爱问知识人...

本文介绍了一个简单的图书管理系统的实现,该系统使用链表来存储图书信息,并提供了创建、插入、删除、浏览、查询和修改图书记录的功能。此外,还实现了将数据保存到文件的功能。

求高手!!

#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):");

展开

全部

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值