| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 552 人关注过本帖
标题:各位高手们 帮我看看这个程序吧 快崩溃了
只看楼主 加入收藏
一个小白
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-6-24
结帖率:100%
收藏
 问题点数:0 回复次数:2 
各位高手们 帮我看看这个程序吧 快崩溃了
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#define size 100
void print_num0();
void print_num1();
void print_num2();
void print_num3();
void print_num4();
void print_num5();
void print_num6();
void print_num7();
void print_num8();
void print_num9();
void print_num11();
int main()
{
printf("******************************************************************************\n");
printf("                         欢迎进入图书管理系统\n");
printf("********************************************************************************\n");
char name[]="admin",passw[]="aaa";
char pname[]="guibin",ppassw[]="aaa";
char usern[10];
char userp[10];
char c;
int j=0;
int l=0;
int getch();
printf("请输入您的姓名:");
gets(usern);
printf("请输入您的密码:");
for(j=0;j!=10;++j);
{userp[j]='\0';}
while((c=getch())!=13)
{
    userp[l++]=c;
    passw[j++]=c;
    putchar('*');
}
userp[l]='\0';
l=0;
printf("\n");
if(strcmp(name,usern)==0&&strcmp(userp,passw)==0)
{printf("登陆成功!\n你是管理员\n");
print_num1();
}
else if(strcmp(name,pname)==0&&strcmp(userp,ppassw)==0)
{printf("登陆成功!\n你是普通会员\n");print_num2();}
else printf("登录失败\n");
   
   
return 0;
}

void print_num0()
{
    system("cls");
    printf("             ==================================================\n");
    printf("             =                                                =\n");
    printf("             =                                                =\n");
    printf("             =                            =\n");
    printf("             =                                                =\n");
    printf("             =                                                =\n");
    printf("             ==================================================\n\n");

    printf("             ==========1.输入图书名浏览相应图书信息========\n\n");
    printf("             ================2.浏览结束====================\n\n");
    char grade;
    printf("                                  您的选择:");
    scanf("%s",&grade);
    switch(grade)
    {case'1':printf("输入图书名浏览相应图书信息\n");print_num11();
     case'2':printf("浏览结束\n");break;
    }
}
void print_num1()
   {
    printf("==1.初始化图书信息=========2.增加图书信息=====================\n");
    printf("==3.修改图书信息===========4.删除图图书信息===================\n");
    printf("==5.按普通价格从高到低浏览图书信息============================\n");
    printf("==6.增加会员信息==============================================\n");
    printf("==7.删除会员信息===========8.按名字浏览会员信息===============\n");
    printf("================0.程序结束====================================\n");
    char n;
    printf("请输入您的选择:");
    scanf("%s",&n);
    switch(n)
    {
    case'1':printf("初始化图书信息\n");print_num3();break;
    case'2':printf("增加图书信息\n");print_num4();break;
    case'3':printf("修改图书信息\n");print_num5();break;
    case'4':printf("删除图书信息\n");print_num6();break;
    case'5':printf("按普通价格从高到低浏览图书信息\n");print_num7();break;
    case'6':printf("增加会员信息\n");print_num8();break;
    case'7':printf("删除会员信信息\n");print_num9();break;
    case'8':printf("按名字浏览会员信息\n");print_num0();break;
    case'0':printf("程序结束\n");break;
    }

}

typedef struct
{
    long number;
    char name[100];
    float price;
   
}Book;

typedef struct
{   long number;
    char name[9];
    char mpass[7];
}memeber;

 void print_num3()
{
    FILE *fp;
    Book boo,show;
    char bookdat[40]="Book";
    int count=0;
    fp=fopen("bookdat","wb+");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    printf("请输入图书的序号、名称、价格\n");
    while(count<=size)
    {
        printf("\n请输入图书的序号:");
        scanf("%ld",&boo.number);
        if(boo.number==0)
            break;
        printf("请输入图书的名称:");
        scanf("%s",boo.name);
        printf("请输入图书的价格:");
        scanf("%f",&boo.price);
        
        if(fwrite(&boo,sizeof(Book),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
        count++;
    }
    if(count>size)
        printf("输入数据已满\n");
    fclose(fp);
    printf("所输入图书信息如下:\n");
    fp=fopen("bookdat","rb");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    printf("序号\t名称\t价格\n");
    while(fread(&show,sizeof(Book),1,fp)!=0)
        printf("%ld\t%s\t%.1f\t%.1f\n",show.number,show.name,show.price);
    fclose(fp);
    }



 void print_num4()
{
    FILE *fp;
    Book boo,show;
    char bookdat[40]="Book";
    int n;
    int count=0;
    fp=fopen("bookdat","wb+");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    printf("请输入图书的序号,查询是否存在\n");
    scanf("%d,&n");
     if(n==boo.number)
     {
         printf("此号已存在!!!请重新输入\n");
        }
        else
        
            printf("此号不存在.请输入图书的序号、名称、价格\n");
    while(count<=size)
    {
        printf("\n请输入图书的序号:");
        scanf("%ld",&boo.number);

        if(boo.number==0)
            break;
        printf("请输入图书的名称:");
        scanf("%s",boo.name);
        printf("请输入图书的价格:");
        scanf("%f",&boo.price);
        
        if(fwrite(&boo,sizeof(Book),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
        count++;
    }
    if(count>size)
        printf("输入数据已满\n");
    fclose(fp);
    printf("所输入图书信息如下:\n");
    fp=fopen("bookdat","rb");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    printf("序号\t名称\t价格\n");
    while(fread(&show,sizeof(Book),1,fp)!=0)
        printf("%ld\t%s\t%.1f\t%.1f\n",show.number,show.name,show.price);
    fclose(fp);
    }

void print_num5()
{
    FILE *fp;
    Book boo,s[size],show,temp;
    char name[9],next,bookdat[40]="Book";
    int recnumber,i,result=0;
    float price;
begin:
    printf("请输入要修改图书价格的名称");
    scanf("%s",name);
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    while(feof(fp)==0)
    {
        if(fread(&temp,sizeof(Book),1,fp)!=0)
        {
            if(strcmp(temp.name,name)==0)
               result=1;   
        }
    }
    if(result==0)
    {
        printf("要修改的图书%s不存在\n",name);
        fclose(fp);
        goto begin;
    }
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    recnumber=0;
    while((fread(&boo,sizeof(Book),1,fp))!=0)
    {
        if(strcmp(boo.name,name)==0)
        {
            printf("请输入要修改图书%s的价格",name);
            scanf("%f",&price);            
            s[recnumber].number=boo.number;
            strcpy(s[recnumber].name,boo.name);
            s[recnumber].price=price;
            recnumber++;
        }
        else
        {
            
            s[recnumber].number=boo.number;
            strcpy(s[recnumber].name,boo.name);
            s[recnumber].price=boo.price;
            recnumber++;
        }
    }
    fclose(fp);
    fp=fopen(bookdat,"wb+");
    if(fp==NULL)
    {
       printf("文件%s打不开\n",bookdat);
       exit(1);
    }
    for(i=0;i<recnumber;i++)
    {
        if(fwrite(&s[i],sizeof(Book),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
    }
    fclose(fp);
    printf("修改成功!\n");
    printf("是否继续修改(y/n)\n");
    next=getchar();
    if(next=='y'||next=='Y')
        goto begin;
    printf("所修改图书信息如下:\n");
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    printf("序号\t名称\t价格\t会员价\t\n");
    while(fread(&show,sizeof(Book),1,fp)!=0)
       printf("%ld\t%s\t%.1f\t%.1f\n",show.number,show.name,show.price);
    fclose(fp);
}
 void print_num6()
 {
    FILE *fp;
    Book boo,s[size],show,temp;
    char name[10],next,bookdat[40]="Book";
    int recnumber,i,result=0;
begin:
    printf("请输入要删除图书的名字");
    scanf("%s",name);
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    while(feof(fp)==0)
    {
        if(fread(&temp,sizeof(Book),1,fp)!=0)
        {
            if(strcmp(temp.name,name)==0)
               result=1;   
        }
    }
    if(result==0)
    {
        printf("要删除的图书%s不存在\n",name);
        fclose(fp);
        goto begin;
    }
    fclose(fp);
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    recnumber=0;
    while((fread(&boo,sizeof(Book),1,fp))!=0)
    {
        if(strcmp(boo.name,name)!=0)
        {
            s[recnumber].number=boo.number;
            strcpy(s[recnumber].name,boo.name);
            s[recnumber].price=boo.price;
            recnumber++;
        }
    }
    fclose(fp);
    fp=fopen(bookdat,"wb+");
    if(fp==NULL)
    {
       printf("文件%s打不开\n",bookdat);
       exit(1);
    }
    for(i=0;i<recnumber;i++)
    {
        if(fwrite(&s[i],sizeof(Book),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
    }
    fclose(fp);
    printf("删除成功!\n");
    printf("是否继续删除(y/n)\n");
    next=getchar();
    if(next=='y'||next=='Y')
        goto begin;
    printf("删除要删除的图书后如下:\n");
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    printf("序号\t名称\t价格\t会员价\n");
    while(fread(&show,sizeof(Book),1,fp)!=0)
        printf("%ld\t%s\t%.1f\t%.1f\n",show.number,show.name,show.price);
    fclose(fp);
}

 void print_num7()
{
    FILE *fp;
    char bookdat[40]="Book";
    Book boo,s[size],show;
    int recnumber,i,j,k;
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    recnumber=0;
    while(fread(&boo,sizeof(Book),1,fp)!=0)
    {
        s[recnumber].number=boo.number;
        strcpy(s[recnumber].name,boo.name);
        s[recnumber].price=boo.price;
        
        recnumber++;
    }
    fclose(fp);
    if(recnumber>1)
    {
        for(i=0;i<recnumber-1;i++)
        {
            k=i;
            for(j=i+1;j<recnumber;j++)
                if(s[k].price<s[j].price)
                    k=j;
            boo.number=s[k].number;
            strcpy(boo.name,s[k].name);
            boo.price=s[k].price;
        
            s[k].number=s[i].number;
            strcpy(s[k].name,s[i].name);
             s[k].price=s[i].price;
             s[i].number=boo.number;
            strcpy(s[i].name,boo.name);
            s[i].price=boo.price;
            
        }
    }
    fp=fopen(bookdat,"wb+");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    for(i=0;i<recnumber;i++)
    {
        if(fwrite(&s[i],sizeof(Book),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
    }
    fclose(fp);
    printf("浏览图书信息如下:\n");
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
       printf("文件%s打不开\n",bookdat);
       exit(1);
    }
   printf("序号\t名称\t价格\t会员价\n");
    while(fread(&show,sizeof(Book),1,fp)!=0)
        printf("%ld\t%s\t%.1f\t%.1f\n",show.number,show.name,show.price);
    fclose(fp);
}

 void print_num8()
{
    FILE *fp;
    memeber boo,show;
    char bookdat[40]="memeber";
    int count=0;
    fp=fopen(bookdat,"ab+");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    printf("请输入会员的序号、名字、密码、权限\n");
    while(count<=size)
    {
        printf("\n请输入会员的序号:");
        scanf("%ld",&boo.number);
        if(boo.number==0)
            break;
        printf("请输入会员的名字:");
        scanf("%s",boo.name);
        printf("请输入会员密码:");
        scanf("%s",boo.mpass);
   
        if(fwrite(&boo,sizeof(memeber),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
        count++;
    }
    if(count>size)
        printf("输入数据已满\n");
    fclose(fp);
    printf("所输入图书信息如下:\n");
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    printf("序号\t姓名\t密码\n");
    while(fread(&show,sizeof(memeber),1,fp)!=0)
        printf("%ld\t%s\t%s\t%d\n",show.number,show.name,show.mpass);
    fclose(fp);
}
void print_num9()
{
    FILE *fp;
    memeber boo,s[size],show,temp;
    char name[10],next,bookdat[40]="memeber";
    int recnumber,i,result=0;
begin:
    printf("请输入要删除会员信息的名字");
    scanf("%s",name);
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    while(feof(fp)==0)
    {
        if(fread(&temp,sizeof(memeber),1,fp)!=0)
        {
            if(strcmp(temp.name,name)==0)
               result=1;   
        }
    }
    if(result==0)
    {
        printf("要删除的会员%s不存在\n",name);
        fclose(fp);
        goto begin;
    }
    fclose(fp);
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    recnumber=0;
    while((fread(&boo,sizeof(memeber),1,fp))!=0)
    {
        if(strcmp(boo.name,name)!=0)
        {
            s[recnumber].number=boo.number;
            strcpy(s[recnumber].name,boo.name);
            strcpy(s[recnumber].mpass,boo.mpass);
        
            recnumber++;
        }
    }
    fclose(fp);
    fp=fopen(bookdat,"wb+");
    if(fp==NULL)
    {
       printf("文件%s打不开\n",bookdat);
       exit(1);
    }
    for(i=0;i<recnumber;i++)
    {
        if(fwrite(&s[i],sizeof(memeber),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
    }
    fclose(fp);
    printf("删除成功!\n");
    printf("是否继续删除(y/n)\n");
    next=getchar();
    if(next=='y'||next=='Y')
        goto begin;
    printf("删除信息后会员信息如下:\n");
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    printf("序号\t姓名\t密码\n");
    while(fread(&show,sizeof(memeber),1,fp)!=0)
       printf("%ld\t%s\t%s\t%d\n",show.number,show.name,show.mpass);
    fclose(fp);
}
void print_num11()
   {
    FILE *fp;
    char bookdat[40]="memeber";
    memeber boo,s[size],show;
    int recnumber,i,j,k;
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    recnumber=0;
    while(fread(&boo,sizeof(memeber),1,fp)!=0)
    {
        s[recnumber].number=boo.number;
        strcpy(s[recnumber].name,boo.name);
        strcpy(s[recnumber].mpass,boo.mpass);
        
        recnumber++;
    }
    fclose(fp);
    if(recnumber>1)
    {
        for(i=0;i<recnumber-1;i++)
        {
            k=i;
            for(j=i+1;j<recnumber;j++)
                if(strcmp(s[k].name,s[j].name)>0)
                    k=j;
            boo.number=s[k].number;
            strcpy(boo.name,s[k].name);
            strcpy(boo.mpass,s[k].mpass);
            
            s[k].number=s[i].number;
            strcpy(s[k].name,s[i].name);
            strcpy(s[k].mpass,s[i].mpass);
            s[i].number=boo.number;
            strcpy(s[i].name,boo.name);
            strcpy(s[i].mpass,boo.mpass);
            
        }
    }
    fp=fopen(bookdat,"wb+");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    for(i=0;i<recnumber;i++)
    {
        if(fwrite(&s[i],sizeof(memeber),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
    }
    fclose(fp);
    printf("浏览会员信息如下:\n");
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
       printf("文件%s打不开\n",bookdat);
       exit(1);
    }
    printf("序号\t姓名\t密码\t权限\n");
    while(fread(&show,sizeof(memeber),1,fp)!=0)
       printf("%ld\t%s\t%s\t%d\n",show.number,show.name,show.mpass);
    fclose(fp);
}我怎么运行不了  求调试 小弟跪求啊
搜索更多相关主题的帖子: void 管理系统 include 
2012-06-27 20:55
一个小白
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-6-24
收藏
得分:0 
小弟又调试了下可以运行了  为甚么输入数据后再打开出现的是BOOK无法打开程序如下 麻烦各位高手了 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
#define size 100
void print_num0();
void print_num1();
void print_num2();
void print_num3();
void print_num4();
void print_num5();
void print_num6();
void print_num7();
void print_num8();
void print_num9();

int main()
{
printf("******************************************************************************\n");
printf("                         欢迎进入图书管理系统\n");
printf("********************************************************************************\n");
char name[]="admin",passw[]="aaa";
char pname[]="guibin",ppassw[]="aaa";
char usern[10];
char userp[10];
char c;
int j=0;
int l=0;
int getch();
printf("请输入您的姓名:");
gets(usern);
printf("请输入您的密码:");
for(j=0;j!=10;++j);
{userp[j]='\0';}
while((c=getch())!=13)
{
    userp[l++]=c;
    passw[j++]=c;
    putchar('*');
}
userp[l]='\0';
l=0;
printf("\n");
if(strcmp(name,usern)==0&&strcmp(userp,passw)==0)
{printf("登陆成功!\n你是管理员\n");
print_num1();
}
else if(strcmp(name,pname)==0&&strcmp(userp,ppassw)==0)
{printf("登陆成功!\n你是普通会员\n");print_num2();}
else printf("登录失败\n");
   
   
return 0;
}

void print_num0()
{
    system("cls");
    printf("             ==================================================\n");
    printf("             =                                                =\n");
    printf("             =                                                =\n");
    printf("             =                            =\n");
    printf("             =                                                =\n");
    printf("             =                                                =\n");
    printf("             ==================================================\n\n");

    printf("             ==========1.输入图书名浏览相应图书信息========\n\n");
    printf("             ================2.浏览结束====================\n\n");
    char grade;
    printf("                                  您的选择:");
    scanf("%s",&grade);
    switch(grade)
    {case'1':printf("输入图书名浏览相应图书信息\n");print_num2();
     case'2':printf("浏览结束\n");break;
    }
}
void print_num1()
   {
    printf("==1.初始化图书信息=========2.增加图书信息=====================\n");
    printf("==3.修改图书信息===========4.删除图图书信息===================\n");
    printf("==5.按普通价格从高到低浏览图书信息============================\n");
    printf("==6.增加会员信息==============================================\n");
    printf("==7.删除会员信息===========8.按名字浏览会员信息===============\n");
    printf("================0.程序结束====================================\n");
    char n;
    printf("请输入您的选择:");
    scanf("%s",&n);
    switch(n)
    {
    case'1':printf("初始化图书信息\n");print_num3();break;
    case'2':printf("增加图书信息\n");print_num4();break;
    case'3':printf("修改图书信息\n");print_num5();break;
    case'4':printf("删除图书信息\n");print_num6();break;
    case'5':printf("按普通价格从高到低浏览图书信息\n");print_num7();break;
    case'6':printf("增加会员信息\n");print_num8();break;
    case'7':printf("删除会员信信息\n");print_num9();break;
    case'8':printf("按名字浏览会员信息\n");print_num0();break;
    case'0':printf("程序结束\n");break;
    }

}

typedef struct
{
    long number;
    char name[100];
    float price;
   
}Book;

typedef struct
{   long number;
    char name[9];
    char mpass[7];
}memeber;

 void print_num3()
{
    FILE *fp;
    Book boo,show;
    char bookdat[40]="Book";
    int count=0;
    fp=fopen("bookdat","wb+");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    printf("请输入图书的序号、名称、价格\n");
    while(count<=size)
    {
        printf("\n请输入图书的序号:");
        scanf("%ld",&boo.number);
        if(boo.number==0)
            break;
        printf("请输入图书的名称:");
        scanf("%s",boo.name);
        printf("请输入图书的价格:");
        scanf("%f",&boo.price);
        
        if(fwrite(&boo,sizeof(Book),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
        count++;
    }
    if(count>size)
        printf("输入数据已满\n");
    fclose(fp);
    printf("所输入图书信息如下:\n");
    fp=fopen("bookdat","rb");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    printf("序号\t名称\t价格\n");
    while(fread(&show,sizeof(Book),1,fp)!=0)
        printf("%ld\t%s\t%.1f\t%.1f\n",show.number,show.name,show.price);
    fclose(fp);
    }



 void print_num4()
{
    FILE *fp;
    Book boo,show;
    char bookdat[40]="Book";
    int n;
    int count=0;
    fp=fopen("bookdat","wb+");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    printf("请输入图书的序号,查询是否存在\n");
    scanf("%d,&n");
     if(n==boo.number)
     {
         printf("此号已存在!!!请重新输入\n");
        }
        else
        
            printf("此号不存在.请输入图书的序号、名称、价格\n");
    while(count<=size)
    {
        printf("\n请输入图书的序号:");
        scanf("%ld",&boo.number);

        if(boo.number==0)
            break;
        printf("请输入图书的名称:");
        scanf("%s",boo.name);
        printf("请输入图书的价格:");
        scanf("%f",&boo.price);
        
        if(fwrite(&boo,sizeof(Book),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
        count++;
    }
    if(count>size)
        printf("输入数据已满\n");
    fclose(fp);
    printf("所输入图书信息如下:\n");
    fp=fopen("bookdat","rb");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    printf("序号\t名称\t价格\n");
    while(fread(&show,sizeof(Book),1,fp)!=0)
        printf("%ld\t%s\t%.1f\t%.1f\n",show.number,show.name,show.price);
    fclose(fp);
    }

void print_num5()
{
    FILE *fp;
    Book boo,s[size],show,temp;
    char name[9],next,bookdat[40]="Book";
    int recnumber,i,result=0;
    float price;
begin:
    printf("请输入要修改图书价格的名称");
    scanf("%s",name);
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    while(feof(fp)==0)
    {
        if(fread(&temp,sizeof(Book),1,fp)!=0)
        {
            if(strcmp(temp.name,name)==0)
               result=1;   
        }
    }
    if(result==0)
    {
        printf("要修改的图书%s不存在\n",name);
        fclose(fp);
        goto begin;
    }
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    recnumber=0;
    while((fread(&boo,sizeof(Book),1,fp))!=0)
    {
        if(strcmp(boo.name,name)==0)
        {
            printf("请输入要修改图书%s的价格",name);
            scanf("%f",&price);            
            s[recnumber].number=boo.number;
            strcpy(s[recnumber].name,boo.name);
            s[recnumber].price=price;
            recnumber++;
        }
        else
        {
            
            s[recnumber].number=boo.number;
            strcpy(s[recnumber].name,boo.name);
            s[recnumber].price=boo.price;
            recnumber++;
        }
    }
    fclose(fp);
    fp=fopen(bookdat,"wb+");
    if(fp==NULL)
    {
       printf("文件%s打不开\n",bookdat);
       exit(1);
    }
    for(i=0;i<recnumber;i++)
    {
        if(fwrite(&s[i],sizeof(Book),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
    }
    fclose(fp);
    printf("修改成功!\n");
    printf("是否继续修改(y/n)\n");
    next=getchar();
    if(next=='y'||next=='Y')
        goto begin;
    printf("所修改图书信息如下:\n");
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    printf("序号\t名称\t价格\t会员价\t\n");
    while(fread(&show,sizeof(Book),1,fp)!=0)
       printf("%ld\t%s\t%.1f\t%.1f\n",show.number,show.name,show.price);
    fclose(fp);
}
 void print_num6()
 {
    FILE *fp;
    Book boo,s[size],show,temp;
    char name[10],next,bookdat[40]="Book";
    int recnumber,i,result=0;
begin:
    printf("请输入要删除图书的名字");
    scanf("%s",name);
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    while(feof(fp)==0)
    {
        if(fread(&temp,sizeof(Book),1,fp)!=0)
        {
            if(strcmp(temp.name,name)==0)
               result=1;   
        }
    }
    if(result==0)
    {
        printf("要删除的图书%s不存在\n",name);
        fclose(fp);
        goto begin;
    }
    fclose(fp);
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    recnumber=0;
    while((fread(&boo,sizeof(Book),1,fp))!=0)
    {
        if(strcmp(boo.name,name)!=0)
        {
            s[recnumber].number=boo.number;
            strcpy(s[recnumber].name,boo.name);
            s[recnumber].price=boo.price;
            recnumber++;
        }
    }
    fclose(fp);
    fp=fopen(bookdat,"wb+");
    if(fp==NULL)
    {
       printf("文件%s打不开\n",bookdat);
       exit(1);
    }
    for(i=0;i<recnumber;i++)
    {
        if(fwrite(&s[i],sizeof(Book),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
    }
    fclose(fp);
    printf("删除成功!\n");
    printf("是否继续删除(y/n)\n");
    next=getchar();
    if(next=='y'||next=='Y')
        goto begin;
    printf("删除要删除的图书后如下:\n");
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    printf("序号\t名称\t价格\t会员价\n");
    while(fread(&show,sizeof(Book),1,fp)!=0)
        printf("%ld\t%s\t%.1f\t%.1f\n",show.number,show.name,show.price);
    fclose(fp);
}

 void print_num7()
{
    FILE *fp;
    char bookdat[40]="Book";
    Book boo,s[size],show;
    int recnumber,i,j,k;
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    recnumber=0;
    while(fread(&boo,sizeof(Book),1,fp)!=0)
    {
        s[recnumber].number=boo.number;
        strcpy(s[recnumber].name,boo.name);
        s[recnumber].price=boo.price;
        
        recnumber++;
    }
    fclose(fp);
    if(recnumber>1)
    {
        for(i=0;i<recnumber-1;i++)
        {
            k=i;
            for(j=i+1;j<recnumber;j++)
                if(s[k].price<s[j].price)
                    k=j;
            boo.number=s[k].number;
            strcpy(boo.name,s[k].name);
            boo.price=s[k].price;
        
            s[k].number=s[i].number;
            strcpy(s[k].name,s[i].name);
             s[k].price=s[i].price;
             s[i].number=boo.number;
            strcpy(s[i].name,boo.name);
            s[i].price=boo.price;
            
        }
    }
    fp=fopen(bookdat,"wb+");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    for(i=0;i<recnumber;i++)
    {
        if(fwrite(&s[i],sizeof(Book),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
    }
    fclose(fp);
    printf("浏览图书信息如下:\n");
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
       printf("文件%s打不开\n",bookdat);
       exit(1);
    }
   printf("序号\t名称\t价格\t会员价\n");
    while(fread(&show,sizeof(Book),1,fp)!=0)
        printf("%ld\t%s\t%.1f\t%.1f\n",show.number,show.name,show.price);
    fclose(fp);
}

 void print_num8()
{
    FILE *fp;
    memeber boo,show;
    char bookdat[40]="memeber";
    int count=0;
    fp=fopen(bookdat,"ab+");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    printf("请输入会员的序号、名字、密码、权限\n");
    while(count<=size)
    {
        printf("\n请输入会员的序号:");
        scanf("%ld",&boo.number);
        if(boo.number==0)
            break;
        printf("请输入会员的名字:");
        scanf("%s",boo.name);
        printf("请输入会员密码:");
        scanf("%s",boo.mpass);
   
        if(fwrite(&boo,sizeof(memeber),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
        count++;
    }
    if(count>size)
        printf("输入数据已满\n");
    fclose(fp);
    printf("所输入图书信息如下:\n");
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    printf("序号\t姓名\t密码\n");
    while(fread(&show,sizeof(memeber),1,fp)!=0)
        printf("%ld\t%s\t%s\t%d\n",show.number,show.name,show.mpass);
    fclose(fp);
}
void print_num9()
{
    FILE *fp;
    memeber boo,s[size],show,temp;
    char name[10],next,bookdat[40]="memeber";
    int recnumber,i,result=0;
begin:
    printf("请输入要删除会员信息的名字");
    scanf("%s",name);
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    while(feof(fp)==0)
    {
        if(fread(&temp,sizeof(memeber),1,fp)!=0)
        {
            if(strcmp(temp.name,name)==0)
               result=1;   
        }
    }
    if(result==0)
    {
        printf("要删除的会员%s不存在\n",name);
        fclose(fp);
        goto begin;
    }
    fclose(fp);
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    recnumber=0;
    while((fread(&boo,sizeof(memeber),1,fp))!=0)
    {
        if(strcmp(boo.name,name)!=0)
        {
            s[recnumber].number=boo.number;
            strcpy(s[recnumber].name,boo.name);
            strcpy(s[recnumber].mpass,boo.mpass);
        
            recnumber++;
        }
    }
    fclose(fp);
    fp=fopen(bookdat,"wb+");
    if(fp==NULL)
    {
       printf("文件%s打不开\n",bookdat);
       exit(1);
    }
    for(i=0;i<recnumber;i++)
    {
        if(fwrite(&s[i],sizeof(memeber),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
    }
    fclose(fp);
    printf("删除成功!\n");
    printf("是否继续删除(y/n)\n");
    next=getchar();
    if(next=='y'||next=='Y')
        goto begin;
    printf("删除信息后会员信息如下:\n");
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
         printf("文件%s打不开\n",bookdat);
         exit(1);
    }
    printf("序号\t姓名\t密码\n");
    while(fread(&show,sizeof(memeber),1,fp)!=0)
       printf("%ld\t%s\t%s\t%d\n",show.number,show.name,show.mpass);
    fclose(fp);
}
void print_num2()
   {
    FILE *fp;
    char bookdat[40]="memeber";
    memeber boo,s[size],show;
    int recnumber,i,j,k;
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    recnumber=0;
    while(fread(&boo,sizeof(memeber),1,fp)!=0)
    {
        s[recnumber].number=boo.number;
        strcpy(s[recnumber].name,boo.name);
        strcpy(s[recnumber].mpass,boo.mpass);
        
        recnumber++;
    }
    fclose(fp);
    if(recnumber>1)
    {
        for(i=0;i<recnumber-1;i++)
        {
            k=i;
            for(j=i+1;j<recnumber;j++)
                if(strcmp(s[k].name,s[j].name)>0)
                    k=j;
            boo.number=s[k].number;
            strcpy(boo.name,s[k].name);
            strcpy(boo.mpass,s[k].mpass);
            
            s[k].number=s[i].number;
            strcpy(s[k].name,s[i].name);
            strcpy(s[k].mpass,s[i].mpass);
            s[i].number=boo.number;
            strcpy(s[i].name,boo.name);
            strcpy(s[i].mpass,boo.mpass);
            
        }
    }
    fp=fopen(bookdat,"wb+");
    if(fp==NULL)
    {
        printf("文件%s打不开\n",bookdat);
        exit(1);
    }
    for(i=0;i<recnumber;i++)
    {
        if(fwrite(&s[i],sizeof(memeber),1,fp)!=1)
        {
            printf("文件%s打不开\n",bookdat);
            exit(1);
        }
    }
    fclose(fp);
    printf("浏览会员信息如下:\n");
    fp=fopen(bookdat,"rb");
    if(fp==NULL)
    {
       printf("文件%s打不开\n",bookdat);
       exit(1);
    }
    printf("序号\t姓名\t密码\t权限\n");
    while(fread(&show,sizeof(memeber),1,fp)!=0)
       printf("%ld\t%s\t%s\t%d\n",show.number,show.name,show.mpass);
    fclose(fp);
}
2012-06-27 21:10
SLD867307194
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2012-7-11
收藏
得分:0 
好长啊。头都看晕了。。。
2012-07-11 10:48
快速回复:各位高手们 帮我看看这个程序吧 快崩溃了
数据加载中...
 
   



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

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