首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

拜托各位告诉小弟我哪错了,求

2013-01-20 
拜托各位告诉我哪错了,急求#includestdio.h#includestdlib.h#includestring.htypedef struct bk { c

拜托各位告诉我哪错了,急求
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct bk { 
char book_num[10]; 
char book_name[10]; 
int book_kc; 
int book_xc; 
struct bk * next; 
}book;

struct bk *l;
void save();
void menu();
void  putin();
void search() ;
void lend(); 
void reback();
void save(char book_num[],char book_name[],int number)
{   FILE *book_fp; 
   struct bk *q ,*t;
   q=l;
  if((book_fp=fopen("book.txt","w"))==NULL) 
{ printf("不能建立图书文件!\n"); return; } 
   t=(struct bk *)malloc(sizeof(struct bk)); 
   strcpy(t->book_num,book_num); 
   strcpy(t->book_name,book_name); 
   t->book_kc=t->book_xc=number; 
   q->next=t;t->next=NULL;
   fwrite(t,sizeof(struct bk),1,book_fp); 

}
void  putin()        
{  struct bk *q;
   int number; 
   int  y=1;
   system("cls");
   while(y)
   {
  printf("请输入您的书的编号:");
  scanf("%s",q->book_num);
  printf("请输入书名:");
  scanf("%s",q->book_name);
  printf("请输入您要存的数量:");
  scanf("%d",number);

  printf("\n是否继续录入(1.继续;0,退出录入):");
  fflush(stdin);
 scanf("%d",&y);
  switch(y)
{
     case 1:putin();
     break;
     case 0:system("cls");menu();
     break;

}
}
     save(q->book_num,q->book_name,number);
}
void search() 
{ struct bk *p; 
  p=l; 
   printf("请输入您的书的编号:");
  scanf("%s",p->book_num);
while(p!=NULL&&strcmp(p->book_num,l->book_num)!=0) 
p=p->next; 
if(p==NULL) printf("\n\t此编号对应的图书不存在!\n"); 
else { printf("\n\t图书编号\t图书名\t库存量\t现存量 \n"); 
printf(" %10s\t %10s\t %d\t %d\t\n",p->book_num,p->book_name,p->book_kc,p->book_xc); 

system("cls");
menu(); 

void lend()
{ struct bk *q; 
  q=l; 
  printf("请输入您的书的编号:");
  fflush(stdin);
  scanf("%s",q->book_num);
while(q!=NULL&&strcmp(q->book_num,l->book_num)!=0) 
   q=q->next; 
   if(q==NULL) 
   printf("\n\t此编号对应的图书不存在!\n"); 
else { printf("\n\t图书编号\t图书名\t库存量\t现存量 \n"); 
printf(" %10s\t %10s\t %d\t %d\t\n",q->book_num,q->book_name,q->book_kc,q->book_xc); 

q->book_xc=q->book_xc-1;
save(q->book_num,q->book_name,q->book_xc);


void reback(){
struct bk *b; 
b=l; 
  printf("请输入您的书的编号:");
  scanf("%s",b->book_num);
  while(b!=NULL&&strcmp(b->book_num,l->book_num)!=0) 
   b=b->next; 
   if(b==NULL) 


   printf("\n\t此编号对应的图书不存在!\n"); 
   else {b->book_xc=b->book_xc+1;
 save(b->book_num,b->book_name,b->book_xc);
   printf("\n您的书几经归还,谢谢!") ;
   }
}
void menu()
{ int lm;
 printf(" \n               *****************************************************                    ");
 printf(" \n                                    ★图书管理系统★                                 ");
 printf(" \n                                       ㈠图书入库                                   ");
 printf (" \n                                                                                                                       ㈡查询图书                                 ");
 printf(" \n                               ㈢图书借阅                                  "); 
 printf(" \n                               ㈣图书归还                                    "); 
 printf(" \n                               ㈤退出系统                                     "); 
 printf(" \n                           按上述1/2/3/4/5数字键选择以上功能                    "); 


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

 scanf("%d",&lm);   
 switch(lm)
{
case 1:putin();
break;
    case 2:search();
    break; 
    case 3:lend();
break; 
case 4:reback();
case 5:break;
}
}

main()
{menu();
return 0;
}
[解决办法]


//改了一些
#include<stdlib.h>
#include<string.h>

typedef struct bk {
char book_num[10]; 
char book_name[10]; 
int book_kc; 
int book_xc; 
struct bk * next; 
}book;

struct bk *l;
void save();
void menu();
void  putin();
void search() ;
void lend(); 
void reback();
void save(char book_num[],char book_name[],int number)
{  
FILE *book_fp; 
struct bk *q ,*t;
q=l;
if((book_fp=fopen("book.txt","wb"))==NULL) 

printf("不能建立图书文件!\n"); 
//return; 

t=(struct bk *)malloc(sizeof(struct bk)); 
strcpy(t->book_num,book_num); 
strcpy(t->book_name,book_name); 
t->book_kc=t->book_xc=number; 
q->next=t;
t->next=NULL;
fwrite(t,sizeof(struct bk),1,book_fp); 

}
void  putin()        
{  
struct bk *q =(struct bk *)malloc(sizeof(struct bk)); 
int number; 
int  y=1;
system("cls");
while(y)
{
printf("请输入您的书的编号:");
scanf("%s",q->book_num);
printf("请输入书名:");
scanf("%s",q->book_name);
printf("请输入您要存的数量:");
scanf("%d",&number);

printf("\n是否继续录入(1.继续;0,退出录入):");
fflush(stdin);
scanf("%d",&y);
switch(y)
{
case 1:
putin();
break;
case 0:
system("cls");
menu();
break;
}
}
save(q->book_num,q->book_name,number);
}
void search() 

struct bk *p; 
p=l; 
printf("请输入您的书的编号:");
scanf("%s",&p->book_num);
while(p!=NULL&&strcmp(p->book_num,l->book_num)!=0)
{
p=p->next; 
}
if(p==NULL)
{
printf("\n\t此编号对应的图书不存在!\n");
}
else 
{
printf("\n\t图书编号\t图书名\t库存量\t现存量 \n"); 
printf(" %10s\t %10s\t %d\t %d\t\n",p->book_num,p->book_name,p->book_kc,p->book_xc); 

system("cls");
menu(); 

void lend()

struct bk *q; 
q=l; 
printf("请输入您的书的编号:");
fflush(stdin);
scanf("%s",q->book_num);
while(q!=NULL&&strcmp(q->book_num,l->book_num)!=0) 
q=q->next; 
if(q==NULL) 
printf("\n\t此编号对应的图书不存在!\n"); 
else 

printf("\n\t图书编号\t图书名\t库存量\t现存量 \n"); 
printf(" %10s\t %10s\t %d\t %d\t\n",q->book_num,q->book_name,q->book_kc,q->book_xc); 



q->book_xc=q->book_xc-1;
save(q->book_num,q->book_name,q->book_xc);


void reback()
{
struct bk *b; 
b=l; 
printf("请输入您的书的编号:");
scanf("%s",b->book_num);
while(b!=NULL&&strcmp(b->book_num,l->book_num)!=0) 
b=b->next; 
if(b==NULL) 
printf("\n\t此编号对应的图书不存在!\n"); 
else 
{
b->book_xc=b->book_xc+1;
save(b->book_num,b->book_name,b->book_xc);
printf("\n您的书几经归还,谢谢!") ;
}
}
void menu()
{

int lm;
printf(" \n               *****************************************************                    ");
printf(" \n                              ★图书管理系统★                                                           ");
printf(" \n                                 ㈠图书入库                                                               ");
printf (" \n                                ㈡查询图书                                                               ");
printf(" \n                                ㈢图书借阅                                                               "); 
printf(" \n                                ㈣图书归还                                                               "); 
printf(" \n                                ㈤退出系统                                                               "); 


printf(" \n                           按上述1/2/3/4/5数字键选择以上功能                                "); 
printf(" \n             *******************************************************               ");

scanf("%d",&lm);   
switch(lm)
{
case 1:
putin();
break;
case 2:
search();
break; 
case 3:
lend();
break; 
case 4:
reback();
case 5:
break;
}
}

void main()
{
l = (struct bk *)malloc(sizeof(struct bk)); 
menu();
return ;
}

热点排行