c语言课程设计_图书管理系统程序
/*12. bookfunction.c源程序*/
/*** bookfunction.c***/
/*添加图书*/
#include "d:\cbook\13\c13_book.c"
void BookAdd()
{
FILE *fp;
Book consultbook;
fp=fopen("book.txt","rb");/*读方式打开文件*/
if(fp==NULL)
fp=fopen("book.txt","wb"); /*写方式打开文件*/
else/*如果有书就添加*/
{
fclose(fp);
fp=fopen("book.txt","ab");/*追加方式打开文件*/
}
ClrScr();/*清屏*/
printf("Intput new book num: ");/*逐个输入新图书的资料*/
gets(consultbook.num);
gotoxy(2,4);
printf("Input new book name: ");
gets(consultbook.name);
gotoxy(2,5);
printf("Please input new book's price: ");
scanf("%d%*c",&consultbook.price);
strcpy(consultbook.person,"");
consultbook.yes=1;/*表示书存在未借出*/
consultbook.next=NULL;
fwrite(&consultbook,sizeof(Book),1,fp);/*块写*/
fclose(fp); /*关闭文件*/
ClrScr();
}
/*图书查询*/
void BookConsult()
{
FILE *fp;
Book consultbook;
char bookname[20]; /*书名*/
int flag=0,i=0;
ClrScr();
gotoxy(2,3);
printf("Input the book name: ");
gets(bookname); /*输入要查询的图书名*/
fp=fopen("book.txt","rb");
if(fp==NULL)/*没找到文件*/
{
ClrScr();
gotoxy(2,3);
printf("Error!");
fclose(fp);
return;
}
else
while(!feof(fp))/*查询图书资料*/
{
fread(&consultbook,sizeof(Book),1,fp);
if(strcmp(consultbook.name,bookname)==0)/*如果查找到*/
{
ClrScr();
gotoxy(2,3+i*5);
printf("This book %s information as follow:",consultbook.name);
gotoxy(2,4+i*5);
printf("This book num is %s",consultbook.num);
gotoxy(2,5+i*5);
printf("This book's price is %d",consultbook.price);
gotoxy(2,6+i*5);
printf("This book's is browwed by %s",consultbook.person);
gotoxy(2,7+i*5);
printf("This book's state is %d",consultbook.yes);
i++;
flag=1; /*查找数据标志*/
}
}
if(flag==0)
{
ClrScr();
gotoxy(2,3);
printf("No found this book");
}
fclose(fp);
}
/*删除图书资料*/
void BookDel()
{
FILE *fp;
Book *head,*p,*q;
char bookname[20];
fp=fopen("book.txt","rb");/*读方式打开文件*/
if(fp==NULL)/*没找到文件*/
{
gotoxy(2,3);
printf("Error!");
&n
相关新闻>>
- 发表评论
-
- 最新评论 更多>>