资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

C语言图书统计函数 c语言 图书馆

急~c语言图书管理

#includestdio.h

网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、成都微信小程序、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了始兴免费建站欢迎大家使用!

#includestring.h

#includeconio.h

#includestdlib.h

#includectype.h

#define STACK_INIT_SIZE 10

#define OK 1

#define TRUE 1

#define FALSE 0

#define ERROR 0

struct student /*定义学生类型,用于存放借出的书籍*/

{

int studentnum,phonenum;

char lendbook[10];

}student[1000];

struct book /*定义书的类型*/

{

char bookname[11];

char publisher[20];

char page;

char year[6];

char status[4];

char name[11];

char author[51];

char booknum;

char bookcreat[10];

char borrownum;

char turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/

}book[1000];

struct car /*借书卡的数据类型*/

{

int carnum;

char studentname[10];

int studentclass;

int studentphone;

}car[100];

addcar()

{

FILE *fp;

int i=0;

double allnum,stillbook,outbook,allmoney,avemoney;

fp=fopen("car.txt","a+");

printf("请你输入学生姓名\n");

scanf("%s",car[i].studentname);

printf("请你输入班级\n");

scanf("%d",car[i].studentclass);

fwrite(car[i],sizeof(struct car),1,fp);

fclose(fp);

printf("注册完毕,任意键返回\n");

fp=fopen("book.txt","r");

avemoney=allmoney/allnum;

fclose(fp);

printf("书籍总数:%ld,已借出的书籍:%ld,在馆的书籍:%ld,书籍贯总金额:%ld,书籍平均价格:%ld",

stillbook,outbook,allmoney,avemoney);

getch();

}

carcount()

{

FILE *fp;

int i,n=0;

fp=fopen("car.txt","r");

for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)

{

printf("第%d张卡卡号:%d 姓名:%s 班级:%d 手机号码:%d\n",

i+1,car[i].carnum,car[i].studentname,car[i].studentclass,car[i].studentphone);

n=n+1;

}

fclose(fp);

printf("目前共有%d本书\n",n);

printf("按任意键\n");

getch();

}

void findbook()

{

FILE *fp;

char bookname[10];

int ture,i,booknum;

fp=fopen("book.txt","r");

printf("请输入你要查找的booknum");

scanf("%d",booknum);

for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)

{

if(strcmp(booknum,book[i].booknum)==0)

{

if(book[i].turefalse==1)

printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);

else

fclose(fp);

return FALSE;

}

else

printf("没有你要查询的书籍\n");

fclose(fp);}

return FALSE;

}

void borrowbook(struct book *m) //借阅图书函数

{

int num;

struct book *b, *b1;

printf("输入要借书的编码:");

scanf("%d",num);

b = searchbook(num); /*调用查找图书结点函数*/

if(b != NULL)

{

if(m-borrownum 10)

{

// b-status = '0';

// b1 = m-book[m-borrownum];

strcpy(b1-name,b-name);

strcpy(b1-author,b-author);

b1-booknum = b-booknum;

strcpy(b1-year,b-year);

b1-page = b-page;

strcpy(b1-publisher,b-publisher);

// b1-price = b-price;

// b1-status = b-status;

m-borrownum++;

printf("%s借书成功!",b-name);

getch();

}

else

{

printf("你已借满10本书.");

getch();

}

}

else

{

printf("没有你要借的书.");

getch();

}

}

huanbook() /*还书函数*/

{

FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/

int i,n;

int carnum,booknum;

char lendbook[10];

printf("请你输入你的卡号\n");

scanf("%d",carnum);

fp=fopen("car.txt","r"); /*读取卡号记录*/

{

if(car[i].carnum==carnum) /*卡号存在,进入下一循环*/

{

n=i;

fclose(fp);

printf("请输入你要还的书的booknum\n");

scanf("%d",booknum);

fp=fopen("record.txt","r");

for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否借阅了输入的书*/

{

if(strcmp(student[i].lendbook,lendbook)==0) /*借阅了该书,进入下一循环,否则出错显示*/

{

fclose(fp);

fp=fopen("record.txt","r");

fp2=fopen("bookl.txt","w");

for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++)

{

if(strcmp(student[i].lendbook,lendbook)==0)

{

continue; /*删除还掉的书的借书记录*/

}

fwrite(student[i],sizeof(struct student),1,fp2); /*写入原来没还的书的记录*/

}

fclose(fp);

fclose(fp2);

fp=fopen("record.txt","w");

fp2=fopen("bookl.txt","r");

for(i=0;fread(student[i],sizeof(struct student),1,fp2)!=0;i++)

{

fwrite(student[i],sizeof(struct student),1,fp); /*将借书记录信息写回*/

}

fclose(fp);

fclose(fp2);

fopen("bookl.txt","w"); /*清临时文件的记录*/

fclose(fp2);

fp=fopen("book.txt","r");

fp2=fopen("bookl.txt","w");

for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/

{

if(i==n)

{

book[i].turefalse=1;

fwrite(book[i],sizeof(struct book),1,fp2); /*将还的书的原来状态设为无人借阅的*/

continue;

}

fwrite(book[i],sizeof(struct book),1,fp2);

}

fclose(fp);

fclose(fp2);

fp=fopen("book.txt","w");

fp2=fopen("bookl.txt","r");

for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)

{

fwrite(book[i],sizeof(struct book),1,fp); /*将临时文件写回*/

}

fclose(fp);

fclose(fp2);

fopen("bookl.txt","w"); /*清临时文件*/

fclose(fp2);

printf("还书完毕,按任意键返回\n");

getch();

return 1;

}

else

printf("你没有借这样的书,任意键返回\n");}/*出错提示*/

fclose(fp);

getch();

return 0;

}

else

printf("系统没这样的卡,和管理员联系,按任意键返回\n");}/*出错提示*/

fclose(fp);

getch();

}

void main()

{

struct book *m;

char ch5;

do

{

printf("---------------欢迎进入图书查询系统!--------------\n");

printf(" 1:注册卡号\n");

printf(" 2: 卡号信息\n");

printf(" 3:按书籍编号查找\n");

printf(" 4: 借书\n");

printf(" 5: 还书\n");

printf(" 0:返回\n");

printf("请输入0--5,其他输入非法!\n");

scanf("%s",ch5);

switch(ch5)

{

case '1':addcar();getch();

case '2':carcount();getch();break;

case '3':findbook();getch();break;

case '4':borrowbook(m );getch();break;

case '5':huanbook();getch();break;

case '0':break;

default:printf("无此操作\n");getch();break;

}

}while(ch5!='0');

//return FALSE;

}

自己改一下,应该没有什么问题的,

C语言读取文件时如何统计函数个数

使用fopen函数打开文件,使用fgetc()一个字符一个字符的读取,然后计数统计就可以啦,fget()从文件指针stream指向的文件中读取一个字符,读取一个字节后,光标位置后移一个字节,这个函数的返回值,是返回所读取的一个字节。如果读到文件末尾或者读取出错时返回EOF。

#includestdio.h

int main()

{

FILE *fp;

char filename[50];

int num=0;

printf("输入一个文件名: ");

gets(filename);

if((fp=fopen(filename,"r"))==NULL)

{

printf("文件打开失败..\n");

return ;

}

while(!feof(fp))fgetc(fp)num++;

printf("%s 文件中共有字符个数: %d\n",filename,num);

fclose(fp);

return ;

}

c语言图书管理系统

#include stdio.h

#include stdlib.h

#include time.h

#include string.h

typedef int BOOL;

typedef struct bookinfo

{

char number[15];/*产品编号*/

char name[30];/*产品名称*/

float price;/*单价*/

char auther[20];/*作者*/

BOOL isExit;/*存在状态*/

char lendername[20];/*借书人姓名*/

char lendersex[2];/*借书人性别*/

char lendernum[15];/*借书人学号*/

}BOOKINFO;

void menu()

{

printf("\n\n\n\n\n\n\n");

printf("\t\t\t图书管理系统\n");

printf("\t\t\t1:新进图书基本信息的输入\n");

printf("\t\t\t2:显示全部记录\n");

printf("\t\t\t3:根据图书名称查询图书基本信息\n");

printf("\t\t\t4:根据图书名称对撤销的图书信息进行删除\n");

printf("\t\t\t5:按照图书名称从小大到排序\n");

printf("\t\t\t6:统计某价格以上的图书数量\n");

printf("\t\t\t7:列出所有未借出去的图书信息\n");

printf("\t\t\t8:退出\n");

}

void choice_1_input_new()/*输入新进的图书信息*/

{

char choice;

FILE *p;

BOOKINFO newbook;

system("cls");

while(1)

{

printf("输入图书编号:");

gets(newbook.number);

printf("输入图书名称:");

gets(newbook.name);

printf("输入图书单价:");

scanf("%f",newbook.price);

while(getchar()!='\n');

printf("输入图书的作者:");

gets(newbook.auther);

printf("输入借书人姓名:");

gets(newbook.lendername);

printf("输入借书人性别:");

gets(newbook.lendersex);

printf("输入借书人学号:");

gets(newbook.lendernum);

printf("是否保存该条书目?(Y/N)\n");

choice=getch();

while(choice!='Y'choice!='y'choice!='N'choice!='n')

choice=getch();

if(choice=='Y'||choice=='y')

{

newbook.isExit=1;/*将图书状态设置成1,表示没有借出*/

p=fopen("c:\\bookinfo.data","ab");

fwrite(newbook,sizeof(BOOKINFO),1,p);

fclose(p);

printf("\n该条书目已添加到c:\\bookinfo.data文件中!\n");

}

else

{

printf("\n本条书目未保存!\n");

}

printf("\n是否继续添加书目?(Y/N)\n");

choice=getch();

while(choice!='Y'choice!='y'choice!='N'choice!='n')

choice=getch();

if(choice=='Y'||choice=='y')

continue;

else

break;

}

}

void choice_2_display_all()/*显示全部图书信息*/

{

FILE *p;

int n;

BOOKINFO bookinfo[100];

int booknumber=0;

system("cls");

p=fopen("c:\\bookinfo.data","rb");

while(!feof(p))

{

fread(bookinfo[booknumber],sizeof(BOOKINFO),1,p);

booknumber++;

}

/*booknumber--;使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/

fclose(p);

booknumber--;

if(booknumber==0)

{

printf("没有任何图书信息!\n\n");

}

else

{

n=0;

printf(" 图书信息如下\n");

printf(" 图书信息 | 借书人信息 \n");

printf("编号 名称 单价 作者 图书状态 | 姓名 性别 学号\n");

while(nbooknumber)

{

printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",

bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,

bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,

bookinfo[n].lendersex,bookinfo[n].lendernum);

n++;

}

}

printf("\n\n按任意键回到主菜单!\n");

getch();

}

void choice_3_search_according_name()/*根据图书名称显示图书的信息*/

{

char search[20]="";/*search用来存放要查询的书名*/

int n;

FILE *p;

char choice;

BOOKINFO bookinfo[100];

int booknumber=0;

system("cls");

p=fopen("c:\\bookinfo.data","rb");

while(!feof(p))

{

fread(bookinfo[booknumber],sizeof(BOOKINFO),1,p);

booknumber++;

}

booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/

fclose(p);

while(1)

{

printf("输入要查询的书本名称:");

gets(search);

if(booknumber==0)

{

printf("书库中没有任何信息!\n\n");

printf("按任意键回到主菜单!\n\n");

getch();

break;

}/*if结束*/

else

{

for(n=0;nbooknumber;n++)

if(strcmp(bookinfo[n].name,search)==0)

{

printf("该书的详细信息如下:\n");

printf(" 图书信息 | 借书人信息 \n");

printf("编号 名称 单价 作者 图书状态 | 姓名 性别 学号\n");

printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",

bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,

bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,

bookinfo[n].lendersex,bookinfo[n].lendernum);

break;

}

if(n=booknumber)

printf("没有查找该书的任何信息!\n");

printf("\n\n是否继续查询?(Y/N)\n");

choice=getch();

while(choice!='Y'choice!='y'choice!='N'choice!='n')

choice=getch();

if(choice=='Y'||choice=='y')

continue;

else

break;

}/*else结束*/

}/*while(1)结束*/

}

void choice_4_delete_according_name()/*根据图书名称对图书信息进行删除*/

{

char search[20]="";/*search用来存放要删除的书名*/

int n,i;

FILE *p;

char choice;

BOOKINFO bookinfo[100];

int booknumber;

system("cls");

while(1)

{

printf("输入要删除的书本名称:");

gets(search);

p=fopen("c:\\bookinfo.data","rb");

booknumber=0;

while(!feof(p))

{

fread(bookinfo[booknumber],sizeof(BOOKINFO),1,p);

booknumber++;

}

booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/

fclose(p);

if(booknumber==0)

{

printf("书库中没有任何信息!\n\n");

printf("按任意键回到主菜单!\n\n");

getch();

break;

}/*if结束*/

else

{

for(n=0;nbooknumber;n++)

if(strcmp(bookinfo[n].name,search)==0)

{

break;

}

if(n=booknumber)

printf("没有查找该书的任何信息!\n");

else

{

printf("是否确认需要删除该条书目?(Y/N)");

choice=getch();

while(choice!='Y'choice!='y'choice!='N'choice!='n')

choice=getch();

if(choice=='Y'||choice=='y')

{

for(i=n;ibooknumber-1;i++)

bookinfo[i]=bookinfo[i+1];

booknumber--;

p=fopen("c:\\bookinfo.data","wb");

for(n=0;nbooknumber;n++)

fwrite(bookinfo[n],sizeof(BOOKINFO),1,p);

fclose(p);

printf("删除成功!\n");

}

else

printf("\n\n该条书目没有被删除!");

}

printf("\n\n是否继续进行删除操作?(Y/N)\n");

choice=getch();

while(choice!='Y'choice!='y'choice!='N'choice!='n')

choice=getch();

if(choice=='Y'||choice=='y')

continue;

else

break;

}/*else结束*/

}/*while(1)结束*/

}

void choice_5_sort_according_name()/*根据图书名称排序*/

{

FILE *p;

int m,n;

BOOKINFO temp;

BOOKINFO bookinfo[100];

int booknumber;

p=fopen("c:\\bookinfo.data","rb");

booknumber=0;

system("cls");

while(!feof(p))

{

fread(bookinfo[booknumber],sizeof(BOOKINFO),1,p);

booknumber++;

}

booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/

fclose(p);

if(booknumber==0)

{

printf("没有任何图书信息!\n\n");

}

else

{

for(m=0;mbooknumber-1;m++)

for(n=m+1;nbooknumber;n++)

if(strcmp(bookinfo[m].name,bookinfo[n].name)0)

{

temp=bookinfo[m];

bookinfo[m]=bookinfo[n];

bookinfo[n]=temp;

}

p=fopen("c:\\bookinfo.data","wb");

for(m=0;mbooknumber;m++)

fwrite(bookinfo[m],sizeof(BOOKINFO),1,p);

fclose(p);

printf("\n\n完成排序!\n\n");

}

printf("按任意键回到主菜单!\n");

getch();

}

void choice_6_display_high_price()/*根据价格列出图书信息*/

{

float price;

FILE *p;

int n;

int count=0;

BOOKINFO bookinfo[100];

int booknumber;

system("cls");

printf("请输入价格:");

scanf("%f",price);

p=fopen("c:\\bookinfo.data","rb");

booknumber=0;

while(!feof(p))

{

fread(bookinfo[booknumber],sizeof(BOOKINFO),1,p);

booknumber++;

}

booknumber--;/*使用feof()函数会多读一行,因此需要booknumber自减一次,使书目的数量正确*/

fclose(p);

if(booknumber==0)

{

printf("没有任何图书信息!\n\n");

}

else

{

for(n=0;nbooknumber;n++)

{

if(bookinfo[n].price=price)

count++;

}

if(count==0)

printf("书库中没有比%.1f$价格高的图书!",price);

else

{

printf(" 价格高于%.1f$的图书信息如下\n",price);

printf(" 图书信息 | 借书人信息 \n");

printf("编号 名称 单价 作者 图书状态 | 姓名 性别 学号\n");

for(n=0;nbooknumber;n++)

{

if(bookinfo[n].price=price)

printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",

bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,

bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,

bookinfo[n].lendersex,bookinfo[n].lendernum);

}

}

}

printf("\n\n按任意键回到主菜单!\n");

getch();

}

void choice_7_display_according_exitflag()/*根据存在状态列出图书信息*/

{

FILE *p;

int n;

int count=0;

BOOKINFO bookinfo[100];

int booknumber;

system("cls");

booknumber=0;

p=fopen("c:\\bookinfo.data","rb");

while(!feof(p))

{

fread(bookinfo[booknumber],sizeof(BOOKINFO),1,p);

booknumber++;

}

booknumber--;

fclose(p);

if(booknumber==0)

{

printf("书库中没有任何书目存在!\n");

}

else

{

for(n=0;nbooknumber;n++)

if(bookinfo[n].isExit==1)

count++;

if(count==0)

printf("书库中的书籍全部借出!\n");

else

{

printf("书库中未被借出的图书信息如下:\n\n");

printf(" 图书信息 | 借书人信息 \n");

printf("编号 名称 单价 作者 图书状态 | 姓名 性别 学号\n");

for(n=0;nbooknumber;n++)

if(bookinfo[n].isExit==1)

{

printf("%-6s%-12s%-8.1f%-8s%-9d| %-12s%-8s%-8s\n",

bookinfo[n].number,bookinfo[n].name,bookinfo[n].price,

bookinfo[n].auther,bookinfo[n].isExit,bookinfo[n].lendername,

bookinfo[n].lendersex,bookinfo[n].lendernum);

}

}

}

printf("\n按任意键返回主菜单!\n");

getch();

}

void main()

{

char choice;

clock_t tm;

FILE *p;

if((p=fopen("c:\\bookinfo.data","rb"))==NULL)

{

p=fopen("c:\\bookinfo.data","wb");

fclose(p);

}

while(1)

{

system("cls");

menu();

choice=getch();

switch(choice)

{

case '1':choice_1_input_new();break;/*输入新进的图书信息*/

case '2':choice_2_display_all();break;/*显示全部图书信息*/

case '3':choice_3_search_according_name();break;/*根据图书名称显示图书的信息*/

case '4':choice_4_delete_according_name();break;/*根据图书名称对图书信息进行删除*/

case '5':choice_5_sort_according_name();break;/*根据图书名称排序*/

case '6':choice_6_display_high_price();break;/*根据价格列出图书信息*/

case '7':choice_7_display_according_exitflag();break;/*根据存在状态列出图书信息*/

case '8':printf("\n\n\t\t\t谢谢使用,再见!\n\t\t\t按任意键退出!\n");getch();return;

default:

printf("\n\n\t\t\t请输入菜单中的数字!(1~8)");

tm=clock();

while(clock()tm+1800);

break;

}

}

}

写的很赶,不知道行不行

程序很长,但是没什么复杂的东西。

要是写的不好,楼主就将就吧。

用C语言编写一个简单的图书管理小程序

源代码如下:

#includeiostream

#includeiomanip

#includestring

#includefstream

#includestdio.h

using namespace std;

const   int   maxb=10000;   //最多的图书

class   book//图书类

{

int   tag;   //删除标记1:已删0:未删

int   number;   //isbn书号

char   name[20];   //书名

char author[10]; //主编

char number2[10];//版次

char position[20];//出版社

char time[20];//出版年

void   addbook(int n,char *na,char *au,char *n2,char *da,char *ti,int pr)   //增加图书  

{

tag=0;

number=n;

price=pr;

strcpy(name,na);

strcpy(author,au);

strcpy(number2,n2);

strcpy(position,da);

strcpy(time,ti);

onshelf=1;

}  

扩展资料

1、源程序中,很多符号都是成对匹配出现的,为避免遗漏必须配对使用的符号。

2、用花括号括起来的部分,但从程序结构清晰,便于阅读、理解、维护的角度出发,建议在书写程序时应遵循以下规则,以养成良好的编程习惯。

3、一个说明或一条语句占一行,与该结构开始处的左花括号对齐。

c语言图书资产统计系统

希望对你有用

#includestdio.h

#includestring.h

#includeconio.h

#includestdlib.h

#includectype.h

#define STACK_INIT_SIZE 10

#define OK 1

#define TRUE 1

#define FALSE 0

#define ERROR 0

struct student /*定义学生类型,用于存放借出的书籍*/

{

int carnum;

char lendbook[10];

}student[1000];

struct employ /*定义职工类型*/

{

int employnum;

char employname[15];

int employage;

char employsex[2];

char employleve[10];

long int employtage;

}employ[50];

struct book /*定义书的类型*/

{

int booknum;

char bookname[10];

char bookcreat[10];

int turefalse; /*用于借书和还书模块判断一本书是否借出的条件*/

}book[1000];

struct car /*借书卡的数据类型*/

{

int carnum;

char studentname[10];

int studentclass;

}car[100];

huanbook() /*还书函数*/

{

FILE *fp,*fp2; /*定义两个文件指针,fp2用于修改数据时设立临时文件用,防止数据遭破坏*/

int i,n;

int carnum;

char lendbook[10];

printf("请你输入你的卡号\n");

scanf("%d",carnum);

fp=fopen("car.txt","r"); /*读取卡号记录*/

for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++) /*for循环判断卡号是否存在*/

{

if(car[i].carnum==carnum) /*卡号存在,进入下一循环*/

{

n=i;

fclose(fp);

printf("请输入你要还的书的名字\n");

scanf("%s",lendbook);

fp=fopen("record.txt","r");

for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++) /*判断是否借阅了输入的书*/

{

if(strcmp(student[i].lendbook,lendbook)==0) /*借阅了该书,进入下一循环,否则出错显示*/

{

fclose(fp);

fp=fopen("record.txt","r");

fp2=fopen("bookl.txt","w");

for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++)

{

if(strcmp(student[i].lendbook,lendbook)==0)

{

continue; /*删除还掉的书的借书记录*/

}

fwrite(student[i],sizeof(struct student),1,fp2); /*写入原来没还的书的记录*/

}

fclose(fp);

fclose(fp2);

fp=fopen("record.txt","w");

fp2=fopen("bookl.txt","r");

for(i=0;fread(student[i],sizeof(struct student),1,fp2)!=0;i++)

{

fwrite(student[i],sizeof(struct student),1,fp); /*将借书记录信息写回*/

}

fclose(fp);

fclose(fp2);

fopen("bookl.txt","w"); /*清临时文件的记录*/

fclose(fp2);

fp=fopen("book.txt","r");

fp2=fopen("bookl.txt","w");

for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++) /*将书的记录写入临时文件,防止因为修改信息破坏以前的记录*/

{

if(i==n)

{

book[i].turefalse=1;

fwrite(book[i],sizeof(struct book),1,fp2); /*将还的书的原来状态设为无人借阅的*/

continue;

}

fwrite(book[i],sizeof(struct book),1,fp2);

}

fclose(fp);

fclose(fp2);

fp=fopen("book.txt","w");

fp2=fopen("bookl.txt","r");

for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)

{

fwrite(book[i],sizeof(struct book),1,fp); /*将临时文件写回*/

}

fclose(fp);

fclose(fp2);

fopen("bookl.txt","w"); /*清临时文件*/

fclose(fp2);

printf("还书完毕,按任意键返回\n");

getch();

return 1;

}

}

printf("你没有借这样的书,任意键返回\n"); /*出错提示*/

fclose(fp);

getch();

return 0;

}

}

printf("系统没这样的卡,和管理员联系,按任意键返回\n"); /*出错提示*/

fclose(fp);

getch();

}

findbook()

{

FILE *fp;

char bookname[10];

int ture,i;

fp=fopen("book.txt","r");

printf("请输入你要查找的书名\n");

scanf("%s",bookname);

for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)

{

if(strcmp(bookname,book[i].bookname)==0)

{

if(book[i].turefalse==1)

{

printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);

}

else

fclose(fp);

return FALSE;

}

}

printf("没有你要查询的书籍\n");

fclose(fp);

return FALSE;

}

findbook1()

{

FILE *fp;

char bookcreat[10];

int ture,i;

fp=fopen("book.txt","r");

printf("请输入你要查找的作者名\n");

scanf("%s",bookcreat);

for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)

{

if(strcmp(bookcreat,book[i].bookcreat)==0)

{

if(book[i].turefalse==1)

{

printf("这本书的详细资料是:%d %s %s 此书现在无人借阅\n按任意键返回\n",book[i].booknum,book[i].bookname,book[i].bookcreat);

}

else

fclose(fp);

return FALSE;

}

}

printf("没有你要查询的书籍\n");

fclose(fp);

return FALSE;

}

lendcount()

{

FILE *fp;

int i,n=0;

fp=fopen("record.txt","r");

for(i=0;fread(student[i],sizeof(struct student),1,fp)!=0;i++)

{

printf("卡号:%d 借出的书籍:%s \n",student[i].carnum,student[i].lendbook);

n=n+1;

}

fclose(fp);

printf("目前共有%d本书借出\n",n);

printf("按任意键\n");

getch();

return n;

}

chabook()

{

char ch5;

do

{

printf("---------------欢迎进入图书查询系统!--------------\n");

printf(" 1:按书名查找\n");

printf(" 2:按作者查找\n");

printf(" 0:返回\n");

printf("请输入0--2,其他输入非法!\n");

scanf("%s",ch5);

switch(ch5)

{

case '1':findbook();getch();break;

case '2':findbook1();getch();break;

case '0':break;

default:printf("无此操作\n");getch();break;

}

}while(ch5!='0');

return FALSE;

}

lendbook()

{

FILE *fp,*fp2;

int i,n;

int carnum;

printf("请你输入你的卡号\n");

scanf("%d",carnum);

fp=fopen("car.txt","r");

for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)

{

if(car[i].carnum==carnum)

{

n=i;

fclose(fp);

printf("请输入你要借阅的书的名字\n");

scanf("%s",student[n].lendbook);

fp=fopen("book.txt","r");

for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)

{

if(strcmp(book[i].bookname,student[n].lendbook)==0)

{

if(book[i].turefalse==0)

else

fclose(fp);

fp=fopen("record.txt","a+");

student[n].carnum=carnum;

fwrite(student[n],sizeof(struct student),1,fp);

fclose(fp);

fp=fopen("book.txt","r");

fp2=fopen("bookl.txt","w");

for(i=0;fread(book[i],sizeof(struct book),1,fp)!=0;i++)

{

if(strcmp(book[i].bookname,student[n].lendbook)==0)

{

book[i].turefalse=0;

fwrite(book[i],sizeof(struct book),1,fp2);

continue;

}

fwrite(book[i],sizeof(struct book),1,fp2);

}

fclose(fp);

fclose(fp2);

fp=fopen("book.txt","w");

fp2=fopen("bookl.txt","r");

for(i=0;fread(book[i],sizeof(struct book),1,fp2)!=0;i++)

{

fwrite(book[i],sizeof(struct book),1,fp);

}

fclose(fp);

fclose(fp2);

fopen("bookl.txt","w");

fclose(fp2);

printf("借书完毕,按任意键返回\n");

getch();

return;

}

}

printf("不存在这样的书,任意键返回\n");

fclose(fp);

getch();

return;

}

}

printf("你的卡号不存在,请申请新卡,按任意键返回\n");

fclose(fp);

getch();

}

carcount()

{

FILE *fp;

int i,n=0;

fp=fopen("car.txt","r");

for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)

{

printf("第%d张卡卡号:%d 姓名:%s 班级:%d\n",i+1,car[i].carnum,car[i].studentname,car[i].studentclass);

n=n+1;

}

fclose(fp);

printf("目前共有%d本书\n",n);

printf("按任意键\n");

getch();

}

delcar()

{

FILE *fp,*fp2;

int i;

int carnum;

char choice;

fp=fopen("car.txt","r");

fp2=fopen("bookl.txt","w");

printf("请输入你要删除的卡号\n");

printf("如果你输入的卡号存在,系统自动删除该信息!如果不存在,系统不做任何改动\n");

scanf("%d",carnum);

for(i=0;fread(car[i],sizeof(struct car),1,fp)!=0;i++)

{

if(car[i].carnum!=carnum)

{

fwrite(car[i],sizeof(struct car),1,fp2);

}

}

fclose(fp);

fclose(fp2);

printf("是否真的要删除该卡?删除后该书籍的所有信息将无法恢复《Y/N》\n");

scanf("%s",choice);

if(choice=='y'||choice=='Y')

{

fp=fopen("car.txt","w");

fp2=fopen("bookl.txt","r");

for(i=0;fread(car[i],sizeof(struct car),1,fp2)!=0;i++)

{

fwrite(car[i],sizeof(struct car),1,fp);

}

fclose(fp);

fclose(fp2);

fp2=fopen("bookl.txt","w");

fclose(fp2);

printf("按任意键返回\n");

getch();

return;

}

else

{

printf("按任意键返回\n");

getch();

return;

}

}

addcar()

{

FILE *fp;

int i=0;

fp=fopen("car.txt","a+");

printf("请你输入卡号\n");

scanf("%d",car[i].carnum);

printf("请你输入学生姓名\n");

scanf("%s",car[i].studentname);

printf("请你输入班级\n");

scanf("%d",car[i].studentclass);

fwrite(car[i],sizeof(struct car),1,fp);

fclose(fp);

printf("输入完毕,任意键返回\n");

getch();

}


本文题目:C语言图书统计函数 c语言 图书馆
链接URL:http://cdkjz.cn/article/doscicj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220