图书馆管理系统


#include"stdio.h"
#include"string.h"

struct  book                                  
{  char  number[20];
   char  name[20];
   char  press[20];
   char  writer[20];
   int   n;                                   
   int   m;                                   
}a[10];

int b;                                        

void input()                                 
{
   FILE *fp;
   char  str2[10]={"     "};
   int i;
   if((fp=fopen("d:\\wen","w"))==NULL)
   {
    printf("Open  failed!\n");
    return;
   }
   printf("\nHow many books do you want to input?\n");
   scanf("%d",&b);
   for(i=0;i    {
    printf("Enter the %d book's number name press writer  now all\n",i+1);
    scanf("%s%s%s%s%d%d",&a[i].number,&a[i].name,&a[i].press,&a[i].writer,&a[i].n,&a[i].m);
    fwrite(&a[i],sizeof(struct book),1,fp);
   }
   fclose(fp);
}

void Search()                                

 FILE *fp; 
    int w,i;                                 
 char str[20];                                                  
 if((fp=fopen("d:\\wen","r"))==NULL)
 {
  printf("Open  failed\n");
      return;
 }
 for(i=0;i     if(fread(&a[i],sizeof(struct book),1,fp)!=1)
  printf("file read error\n");
    printf("search by number--6\n");
    printf("search by name--7\n");
    printf("search by writer--8\n");
    printf("search by press--9\n");
    scanf("%d",&w);
 printf("Enter the word you want to search:\n");
    scanf("%s",str);
 switch(w)
 {
  case 6:
     {
   for(i=0;i       if(strcmp(a[i].number,str)==0)
   {
    printf("number: %s  name:  %s  press:  %s  writer:  %s  now:  %d  all:%d\n",a[i].number,a[i].name,a[i].press,a[i].writer,a[i].n,a[i].m);
    break;
   }
     }
  break;
     case 7:
  { 
   for(i=0;i          if(strcmp(a[i].name,str)==0)
      {
    printf("number: %s  name:  %s  press:  %s  writer:  %s  now:  %d  all:%d\n",a[i].number,a[i].name,a[i].press,a[i].writer,a[i].n,a[i].m);
        break;
    }
     

你可能感兴趣的:(C语言课程设计)