以下是引用jinzhu0505在2011-6-3 15:01:08的发言:
主函数呢?Pbook是什么变量的定义啊?
pbook是结构体指针
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct node{
long num;
char name[30];
long stu_num;
char stu_name[10];
int lent_out;
struct node *next;
struct node *pioneer;
}book,*pbook;
FILE *fp;
int insert_newbook(pbook head,int count);
int delete_book(pbook head,int count);
void lendout_book(pbook head);
void return_book(pbook head);
void search_book(pbook head);
void printf_bookinfo(pbook head);
void reserve_book(pbook head,long count);
void warning(pbook head,long count);
int creat_bookinfofile()
{
//fp=fopen("librarymaster.dat","a+");
if((fp=fopen("librarymaster.dat","ab+"))!=NULL)
{
return 1;
}
else
return 0;
}
pbook creat_node(void)
{
pbook head;
head=(pbook)malloc(sizeof(book));
if(head)
head->next=NULL;
return head;
}
int main(void)
{
int choice,i;
pbook head,newdata,tail;
char a[4],bookname[30],studentname[10];
int booknum,studentnum,lentout;
long size,len,count;
head=creat_node();
if(creat_bookinfofile())
printf("新建成功\n");
else
{
printf("打开失败,系统将关闭\n");
system("pause");
exit(0);
// goto exitbookmaster;
}
fseek(fp,0L,SEEK_END);
len=ftell(fp);
size=sizeof(book);
count=len/size;
fseek(fp,0L,SEEK_SET);
tail=(pbook)malloc(sizeof(book));
head->next=tail;
tail->pioneer=head;
tail->next=NULL;
for(i=1;i<=count;i++)
{
// fseek(fp,size,SEEK_CUR);
newdata=(pbook)malloc(sizeof(book));
fread(newdata,size,1,fp);
newdata->next=tail;
newdata->pioneer=tail->pioneer;
tail->pioneer->next=newdata;
tail->pioneer=newdata;
}
clearerr(fp);
if(fclose(fp))
{
printf("关闭文件失败,强制退出程序\n");
system("pause");
//goto exitbookmaster;
exit(0);
}
do{
printf("╔══════════════════════════════════╗\n");
printf("║ 欢迎使用图书管理系统㊣by 罗枭 ║\n");
printf("╠══════════════════════════════════╣\n");
printf("║1、新增图书信息 2、删除图书信息║\n");
printf("║3、图书借出 4、图书归还 ║\n");
printf("║5、搜索图书 6、显示图书信息║\n");
printf("║7、保存图书信息 0、退出管理系统║\n");
printf("╚══════════════════════════════════╝\n");
scanf("%d",&choice);
switch(choice)
{
case 1:count=insert_newbook(head,count); break;
case 2:count=delete_book(head,count); break;
case 3:lendout_book(head); break;
case 4:return_book(head); break;
case 5:search_book(head); break;
case 6:printf_bookinfo(head); break;
case 7:reserve_book(head,count); break;
case 0:warning(head,count); break;
}
system("cls");
printf("您刚才已进行操作 %d\n",choice);
}while(choice!=0);
fclose(fp);
system("pause");
return 0;
}
这个就是主函数