| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 638 人关注过本帖
标题:[求助]小弟最近刚写完一个图书管理程序 请高手帮我看哪里出错了 急需 谢谢
取消只看楼主 加入收藏
xiaoggang
Rank: 1
等 级:新手上路
帖 子:8
专家分:0
注 册:2005-11-21
收藏
 问题点数:0 回复次数:0 
[求助]小弟最近刚写完一个图书管理程序 请高手帮我看哪里出错了 急需 谢谢

#include <dos.h>
#include <bios.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define DOWN 0x5000
#define UP 0x4800
#define SPACE 0x3920
#define ESC 0x011b
#define ENTER 0x1c0d
#define Backspace 0xe08
#define ALT_B 12288
#define ALT_H 8960
int key;
int textx,texty;
struct menustruct
{
char name[10];
char str[10][20];
int n;
}ml[2];
typedef struct BookList
{
char num[20];
char name[20];
char publisher[20];
int price;
struct BookList *next;
}Book;
char save[4096];
char c[4096];
int i,j;
main(void)
{
Menu();
Run();
}

Menu()
{
system("cls");
textbackground(BLUE);
window(1,1,25,80);
clrscr();
textx=3;
texty=2;
gotoxy(1,2);
printf("%c",218);
for(i=0;i<78;i++)
printf("%c",196);
printf("%c",191);
for(i=3;i<=23;i++)
{
gotoxy(1,i);
printf("%c",179);
gotoxy(80,i);
printf("%c",179);
}
printf("%c",192);
for(i=0;i<78;i++)
printf("%c",196);
printf("%c",217);
gotoxy(1,1);
textcolor(7);
for(i=0;i<80;i++)
cprintf("%c",219);
Selectitem();
DrawSelectitem();
gettext(2,3,78,23,c);
}
Selectitem()
{
strcpy(ml[0].name,"Book");
strcpy(ml[0].str[0],"Add ");
strcpy(ml[0].str[1],"Search ");
strcpy(ml[0].str[2],"Xiugai ");
strcpy(ml[0].str[3],"New ");
strcpy(ml[0].str[4],"Delete ");
strcpy(ml[0].str[5],"Save ");
strcpy(ml[0].str[6],"Exit ");
ml[0].n=7;
strcpy(ml[1].name,"Help");
strcpy(ml[1].str[0],"This System ");
strcpy(ml[1].str[1],"Ver ");
ml[1].n=2;
}
DrawSelectitem()
{
for(i=0;i<2;i++)
RedText(i,1,ml[i].name);

}
RedText(int x,int y,char *z)
{
textbackground(7);
gotoxy(3+x*15,y);
for(j=0;z[j];j++)
{
if(j==0)
textcolor(RED);
else
textcolor(BLACK);
cprintf("%c",z[j]);
}
}
BlackText(int x,int y,char *z)
{
textbackground(0);
textcolor(15);
gotoxy(3+15*x,y);
cputs(z);
}
Run()
{
while(1)
{
gotoxy(texty,textx);
key=bioskey(0);
switch(key)
{
case ALT_B:Draw(0);break;
case ALT_H: Draw(1);break;
case UP:
{
if(textx==3)
textx=23;
textx--;
gotoxy(texty,textx);
}break;
case DOWN:
{
if(textx==23)
textx=3;
textx++;
gotoxy(texty,textx);
}break;
case LEFT:
{
if(texty==2)
texty=79;
texty--;
gotoxy(texty,textx);
}break;
case Backspace:
{
if(texty==2&&textx==3)
continue;
else
{
if(texty!=2)
texty--;
else
if(texty==2)
{
texty=78;
textx--;
}
gotoxy(texty,textx);
printf(" ");
gotoxy(texty,textx);
}
}break;
case RIGHT:
{
if(texty==79)
texty=2;
texty++;
gotoxy(texty,textx);
}break;
case SPACE:
{
if(texty==79)
continue;
else
{
gotoxy(texty,textx);
printf(" ");
texty++;
gotoxy(texty,textx);
}
}break;
case ENTER:
{
if(textx==23)
continue;
textx++;
texty=2;
gotoxy(texty,textx);
}break;
default :
{
if(texty==79&&textx==23)
continue;
else
if(texty==79&&textx!=23)
{
textx++;
texty=2;
}
gotoxy(texty,textx);
printf("%c",key);
if(texty==79)
continue;
else
texty++;
}
}
}
}
Draw(int n)
{
gettext(1,1,80,25,save);
BlackText(n,1,ml[n].name);
for(i=3;i<3+ml[n].n;i++)
{
if(i==3)
BlackText(n,i,ml[n].str[i-3]);
else
RedText(n,i,ml[n].str[i-3]);
}
gotoxy(79,1);
Move(n,3);
}
Move(int n,int x)
{
int flag=1;
while(flag)
{
gotoxy(79,1);
key=bioskey(0);
gotoxy(79,1);
switch(key)
{
case ESC:
puttext(1,1,80,25,save);
flag=0;
break;
case LEFT:
puttext(1,1,80,25,save);
if(n==0)
Draw(1);
else
Draw(n-1);
flag=0;
break;
case RIGHT:
puttext(1,1,80,25,save);
if(n==1)
Draw(0);
else
Draw(n+1);
flag=0;
break;
case UP:
RedText(n,x,ml[n].str[x-3]);
if(x==3)
x=3+ml[n].n-1;
else
x--;
BlackText(n,x,ml[n].str[x-3]);
flag=1;
break;
case DOWN:
RedText(n,x,ml[n].str[x-3]);
if(x==(3+ml[n].n-1))
x=3;
else
x++;
BlackText(n,x,ml[n].str[x-3]);
flag=1;
break;
case ENTER:
puttext(1,1,80,25,save);
Enter(n,x-3);
flag=0;
break;
}
gotoxy(79,1);
}
}
Enter(int m,int n)
{
switch(m)
{
case 0:switch(n)
{
case 0:add();break;
case 1:search();break;
} }
}
add()
{ FILE *fp;
Book booklist;
fp=fopen("book.txt","rb");
if(fp==NULL)
fp=fopen("book.txt","wb");
else
{fclose(fp);
fp=fopen("book.txt","ab");
}
gotoxy(2,3);
printf("Input a new book name:");
gets(booklist.name);
gotoxy(2,4);
printf("Input a new book num:");
gets(booklist.num);
gotoxy(2,5);
printf("Input a new book's publisher:");
gets(booklist.publisher);
gotoxy(2,6);
printf("Input a new book price:");
scanf("%d",&booklist.price);
fwrite(&booklist,sizeof(Book),1,fp);
fclose(fp);
Clrcle();
}
Clrcle()
{ int i,j;
puttext(2,3,78,23,c);
gotoxy(2,3);
}
search()
{
FILE *fp;
Book booklist;
char bookname[20];
int flag=1,i=0;
Clrcle();
gotoxy(2,3);
printf("Input the book name: ");
gets(bookname);
fp=fopen("book.txt","rb");
if(fp==NULL)
{
Clrcle();
gotoxy(2,3);
printf("Error!");
fclose(fp);
return;
}
else
while(!feof(fp))
{
fread(&booklist,sizeof(Book),1,fp);
if(strcmp(booklist.name,bookname)==0)
{
Clrcle();
gotoxy(2,3+i*5);
printf("This book %s information as follow:",booklist.name);
gotoxy(2,4+i*5);
printf("This book num is %s",booklist.num);
gotoxy(2,5+i*5);
printf("This book's price is %d",booklist.price);
gotoxy(2,6+i*5);
printf("This book's publisher is %s",booklist.publisher);
i++;
flag=1;
}
}
if(flag==0)
{
Clrcle();
gotoxy(2,3);
printf("No found this book");
}
fclose(fp);
}
save()
{ FILE *fp;
Book booklist;
if(fopen("book.txt","wr")==NULL)
{printf("error");
exit(0);
}
else
{getchar();
fwrite(&booklist,sizeof(Book),1,fp);
return;
}
fclose(fp);
}
new()
{ FILE *fp;
Book booklist;
fp=fopen("book.txt","rb");
if(fp==NULL)
fp=fopen("book.txt","wb");
else
{fclose(fp);
fp=fopen("book.txt","ab");
}
gotoxy(2,3);
printf("Input a new book name:");
gets(booklist.name);
gotoxy(2,4);
printf("Input a new book num:");
gets(booklist.num);
gotoxy(2,5);
printf("Input a new book's publisher:");
gets(booklist.publisher);
gotoxy(2,6);
printf("Input a new book price:");
scanf("%d",&booklist.price);
fwrite(&booklist,sizeof(Book),1,fp);
fclose(fp);
Clrcle();
}
xiugai()
{ FILE *fp;
Book booklist;
int choice;
char bookname[10];
fp=fopen("book.txt","wr");
fread(&booklist,sizeof(Book),1,fp);
printf("qing shuru yao xiugai de shuming:");
scanf("%s",&bookname);
if(strcmp(booklist.name,bookname)==0)
{gotoxy(2,3);
printf("qing xuanze yao xiugai de neirong:");
gotoxy(2,4);
printf("shuming:(%s) shuhao:(%d) price:(%d)publisher (%s) \n",bookname,booknum,price,publisher);
gotoxy(2,5);
printf("1:xiugai shu de mingzi");
gotoxy(2,6);
printf("2:xiugai shu de num");
gotoxy(2,7);
printf("3:xiugai shu de pirce");
gotoxy(2,8);
printf("4:xiugai shu de publisher");
gotoxy(2,9);
printf("qing shuru 0-4:");
scanf("%s",&choice);
switch(choice)
{ case '1':
````{printf("qing shuru xin de shuming:");
` scanf("%s",bookname);
fwrite(&booklist,sizeof(Book),1,fp);
}break;
case '2':
{printf("qing shuru xin de shunum:");
` scanf("%s",booknum);
fwrite(&booklist,sizeof(Book),1,fp);
}break;
case '3':
{printf("qing shuru xin de shu price:");
` scanf("%s",price);
fwrite(&booklist,sizeof(Book),1,fp);
}break;
case '4':
{printf("4:xiugai shu de publisher");
scanf("%s",publisher);
fwrite(&booklist,sizeof(Book),1,fp);
}break;
defaut:printf("meiyou zheyang de caozuo");
}
fclose(fp);
}
void Help()
{
Clrcle();
gotoxy(15,6);
cprintf("click menu to run each funtion");
getch();
Clrcle();
}
void Ver()
{
Clrcle();
gotoxy(15,6);
cprintf("This is finished by wang leigang");
getch();
Clrcle();
}

[此贴子已经被作者于2005-12-30 22:33:09编辑过]

搜索更多相关主题的帖子: 管理程序 图书 
2005-12-30 22:31
快速回复:[求助]小弟最近刚写完一个图书管理程序 请高手帮我看哪里出错了 急需 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017224 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved