⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 能运行c程序.txt

📁 这是我编的图书管理系统
💻 TXT
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void next(int n);
void incr();/*添加*/
void dele();/*删除*/
void disp();/*显示*/
void bore(char);/*借与还*/
void sread(char *);/*文件读到缓冲区*/
void swrite(char *);/*缓冲区写到文件*/
void h()
{printf("********************************************\n");}
void mh()
{h();printf("library manage system\n");h();}
void sread(char *cache)
{ FILE *fp;
char ch;
int i=0;
if((fp=fopen("data.txt","r"))==NULL) exit(0);
while((ch=fgetc(fp))!=EOF) cache[i++]=ch;cache[i]='\0';fclose(fp);}
void swrite(char *cache)
{ FILE *fp;
char ch;
int i=0;
if((fp=fopen("data.txt","w"))==NULL) exit(0);
while((ch=cache[i++])!='\0') fputc(ch,fp);fclose(fp);}
int mainview()
{   int c;
    clrscr();
    mh();printf("main menu\n");h();
    printf("1.increase record\n");
    printf("2.delete record\n");
    printf("3.display record\n");
    printf("4.borrow books\n");
    printf("5.return books\n");
    printf("0.quit\n");h();
    printf("select:");
    do{scanf("%d",&c);
    fflush(stdin);
    if(c<7&&c>=0)break;
    printf("input error!\nreselect:");}
    while(1);
    if(c==0){clrscr();h();puts("thank for useing,please type any exit\n");
    h();getch();exit(0);}
    else return c;}
void next(int n)
{ clrscr();mh();
    switch(n)
    { case 1 :incr();break;
      case 2 :dele();break;
      case 3 :disp();break;
      case 4 :bore('b');break;
      case 5 :bore('a');break;   }}
void incr()
{ char a[50];
   FILE *fp;
   char ch;
   printf("increase record\n"); h();
        if((fp=fopen("data.txt","a"))==NULL)
        fp=fopen("data.txt","w");
        printf("\t**please type \',\' separation**\n"); h();
        printf("**booknumber**bookname**bookdata\n");
        do
        {gets(a); fflush(stdin); h();
        fputs(a,fp);fputs("\ta\n",fp);
        printf("continue?y/n: ");
        scanf("%c",&ch); fflush(stdin);
        }while(ch=='y'||ch=='Y'||ch=='\n');
        fclose(fp); next(mainview());}
void dele()
{   int j=0,i=0,k=0;
    char *cache=NULL,*temp=NULL;
    char tej[4],tes[4]="\0",ch;
    printf("delete record\n"); h();
    printf("input number:");
    gets(tej); fflush(stdin); sread(cache);
        while (cache[i]!='\0')
        {   j=0;
            while((ch=cache[i++])!=',') tes[j++]=ch;j=0;
            if(!strcmp(tes,tej)){while(cache[i++]!='\n');puts(tes);continue;}
            while((ch=tes[j++])!='\0') {temp[k++]=ch;}
            temp[k++]=',';
            while((temp[k++]=cache[i++])!='\n');        }
        temp[k]='\0'; swrite(temp);
        printf("deleted a record\n");
        puts(temp); getch();        
     next(mainview());}
void disp()
{ char *cache=NULL;
    printf("display record\n"); h();
    sread(cache);puts(cache);getch();
    next(mainview());}
void bore(char n)
{   int j=0,i=0;
    char *cache=NULL;
    char tej[4],tes[4]="\0",ch;
    printf("borrow books\n"); h();
        printf("input number:");
        gets(tej);fflush(stdin);sread(cache);
        while (cache[i]!='\0')
        {   j=0;
            while((ch=cache[i++])!=',') tes[j++]=ch;
            if(!strcmp(tes,tej)){while(cache[i++]!='\t');
            if(n!=cache[i])cache[i]=n;else n='c';
            i+=2;continue;}
            while(cache[i++]!='\n');       }
        swrite(cache); puts(cache);
        if (n=='b')    printf("\nborrowed a book");
        else if(n=='c')   printf("\nsorry,borrowed,can\'t agin");
        else                printf("\nreturned a book,thanks!");
        getch(); next(mainview());}
int main()
{
    next(mainview());
}
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -