| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 713 人关注过本帖
标题:急急!各位大虾帮帮忙啊!程序运行的时候有点问题!
只看楼主 加入收藏
li0605020322
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-6-23
收藏
 问题点数:0 回复次数:5 
急急!各位大虾帮帮忙啊!程序运行的时候有点问题!
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <stdlib.h>
#include <dos.h>
#include <conio.h>
#include <process.h>
struct date //日期
{
    int month;
    int day;
    int year;
};


struct BookList //图书结构体
{
    char name[20]; //书名
    char editor[20]; //主编
    char publisher[20]; //出版社
    struct date publish; //出版日期
    float price; //定价
    int user_number; //借阅人借阅证号
    struct date lend; //借阅日期
    int booking_number; //借阅预约人借阅证号
    char borrowname[20];//借阅人用户名
    char ordername[20];//预约人用户名
    struct date booking; //预约日期
    int okay;//遗损情况:1,完好;2,损坏;3,遗失 //损毁情况
    int yes;//判断书是否已经被借出或预约:0,已被预约;1,可借出或预约;2,已被预约
}Book[1000];;
struct StudentList //用户//日期
{
    char name[20];//用户名
    char password[16];//密码
}Student[1000];
void mainpage();//主页面
void main();
void page_title();
void second();//成功登录后的界面
void BookBorrow();//借阅图书
void BookSearch();//查找图书信息
void Booking();//预约图书
void BookReturn();//归还图书
void Bookleft();//遗损处理
void AddBooks();//新书入库
void page_title(char *menu_item) /*编辑主菜单界面*/
{
    system("cls"); /*清除文本模式窗口*/
    printf("********************************************************************************\n");
    printf("********************************************************************************\n");
    printf("******* *******\n");
    printf("******* 欢迎使用图书管理系统 *******\n");
    printf("******* *******\n");
    printf("********************************************************************************\n");
    printf("********************************************************************************\n");
}
inputPW(char * s,int len) //自己写的密码输入的函数
{
    int i;
    fflush(stdin); //清输入流 跟flushall()类似
    for(i=0; ;i++)
    {
        s[i]=getch();
        if(s[i]==13) //输入结束 不能用=='\n'来判断!!
            //因为对于回车来说getchar()='\n'=10;而getch()=13 !='\n' 这个要知道!
            break;
        if(s[i]==8 && i>0) //如果用户按退格键 并且要有格可退时候
        {
            printf("\b \b"); //显示退一格
            i=i-2; //输入数据退2(因为for循环体会加1 所以实际就是退了1)
            continue;
        }
        if(i==len) {i--; continue;}
        printf("*");
    }
    s[i]='\0';
    //末尾补\0 所以该密码实际有效长度为i-1;定义有效长为len 实际定义的串长为len+1
}    
void main() //主函数
{
    
    char user[10],admin[]="1";
    char str[9],pass_word[]="1";
          int i=0,j;
          for (j=0;j<4;j++){
              page_title("\t\t\t\t 登 陆 窗 口 \t\t\t\t");
              printf("\n\n\n\n\n\n\t\t\t用户名:");
              gets(user);          
              printf("\n\t\t\t密码:");
              inputPW(str,8);
              if(strcmp(str,pass_word)!=0||strcmp(user,admin)!=0)
              {printf("\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t\t密码错误,请重新输入\n");
              if (i<3)
              {printf("\t\t\t\t\t\t\t您还可输入%d次\n",3-i);i++;getch();}
              else printf("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t请找相关部门取回密码\n");}
              else
              {
                  printf("\n\n\n\n\n\n\t\t\t\t登陆成功\n");
                  getch();
                  printf("\n\n\t\t\t\t欢迎进入系统\n");
                  getch();
                  second();
          }
          }
          getch();
}


void second()//成功登录后的界面
{
    char j;
    int i,leap=0;
    printf("********************************************************************************\n");
    printf("********************************************************************************\n");
    printf("******* *******\n");
    printf("******* 欢迎进入桂林电子科技大学信息科技学院图书馆 *******\n");
    printf("******* *******\n");
    printf("********************************************************************************\n");
    printf("********************************************************************************\n");
    printf("\n按数字键选择您所需的服务:");
    printf("\n@ 1:借阅图书\n@ 2:预约图书\n@ 3: 归还图书\n@ 4: 查询图书\n@ 5: 新书入库\n@ 6:退出\n\n");
    printf("\n您的选择是:");
    scanf("%c",&j);
    (int)i=j;
    do
    {
        switch(i)
        {
        case 1:printf("\n");BookBorrow();break;
        case 2:printf("\n");Booking();break;
        case 4:printf("\n");BookSearch();break;
        case 5:printf("\n"); AddBooks();break;
        case 6:printf("\n");break;
        default:scanf("%d",&i);leap=1;
        }
    }while(leap==1);
}

void BookBorrow()//借阅图书
{
    FILE *fp;
    // time_t am;//测试
    char bookname[40];
    int i,j,w,flag=0;
    if((fp=fopen("books_list.txt","rb"))==NULL)
    {
        printf("\n无法打开该文件! ");
        return;
    }
    else
        for(w=0;w<1000;w++)
        {fread(&Book[w],sizeof(struct BookList),1,fp);}
        fclose(fp);
        printf(" 借书\n");
        printf("\n请输入图书名:");
        scanf("%s",bookname);
        //getchar();
        for(i=0;i<1000;i++)
        {
            if((strcmp(Book[i].name,bookname))==0)
            { //printf("ghdfghdfsg");
                flag=1;
                if(Book[i].okay==1)
                {
                    if(Book[i].yes==1)
                    {
                        strcpy(Book[i].borrowname,Student->name);
                        Book[i].yes=0;
                        fp=fopen("books_list.txt","wb");
                        for(j=0;j<1000;j++)
                            fwrite(&Book[j],sizeof(struct BookList),1,fp);
                        fclose(fp);
                        printf("\n借书成功!\n*为了其他用户也能即使借阅这本书,请您于一个月内归还此书。多谢合作!*\n");
                        second();
                    }
                    else
                    {
                        printf("\n该书已被借出或已被预约\n");
                        second();
                    }
                }
                else
                {
                    printf("该书已遗损!\n");
                    second();
                }
            }
        }
        if(flag==0)
        {
            printf("该书不存在!\n");
            second();
        }
}
void BookSearch()//查找图书信息
{
    int i,flag;
    char bookname[20];
    FILE *fp;
    if((fp=fopen("books_list.txt","rb"))==NULL)
    {
        printf("\n不能打开该文件");
        return;
    }
    else
    {
        printf(" *********************\n");
        printf(" * 图 书 信 息 查 询 *\n");
        printf(" *********************\n");
        printf("\n请输入书名:\n");
        scanf("%s",bookname);
        while(!feof(fp))
        {
            for(i=0;strlen(Book[0].name)!=0;i++)
                fread(&Book[0],sizeof(struct BookList),1,fp);
            fclose(fp);
            for(i=0;i<1000;i++);
            {
                if(strlen(Book[i].name)==0) break;
                else
                    if(strcmp(bookname,Book[i].name)==0)
                    {
                        printf("\n\n已查到该书,其资料如下:");
                        printf("\n书名:%s",Book[i].name);
                        printf("\n主编:%s",Book[i].editor);
                        printf("\n出版社:%s",Book[i].publisher);
                        printf("\n出版日期:%s",Book[i].publish);
                        printf("\n定价:%f",Book[i].price);
                        printf("\n借阅人用户名:%s",Book[i].borrowname);
                        printf("\n预约人用户名:%s",Book[i].ordername);
                        printf("\n该书现在状况:%s",Book[i].okay);
                        printf("\n这本书的标记:0已借出,1可借出可预约,2已预约:%d",Book[i].yes);
                        flag=1;
                        break;
                    }
            }
        }
    }
    if(flag==0)
        printf("\n\n查无此书。");
    fclose(fp);
    second();
}

void BookReturn()//归还图书
{
}

void Bookleft()//遗损处理
{
}
void AddBooks()//新书入库
{
    FILE *fp;
    if((fp=fopen("books_list.txt","r"))==NULL)
    {
        printf("file not exit");
        if((fp=fopen("books_list.txt","w"))==NULL)
        {
            printf("new file fail!!");
            exit(0);
        }
    }
    else
    {
        
        if((fp=fopen("books_list.txt","a"))==NULL)
        {printf("file add fail!\n");
        exit(0);}
    }
    printf(" !!!!!!!!!!!!!!!!!!!\n");
    printf(" !! 新 书 入 库 !!\n");
    printf(" !!!!!!!!!!!!!!!!!!!\n");
    printf("\n请输入新书的名字: ");
    scanf("%s",&Book[1].name);
    printf("\n请输入新书的主编:");
    scanf("%s",&Book[1].editor);
    printf("\n请输入新书的出版社:");
    scanf("%s",&Book[1].publisher);
    printf("\n请输入新书的出版日期:格式为(2006 12 31):");
    scanf("%s%s%s",&Book[1].publish.year,&Book[1].publish.month,&Book[1].publish.day);
    printf("\n请输入新书的定价:");
    scanf("%f",&Book[1].price);
    Book[1].okay=1;
    Book[1].yes=1;
    fwrite(&Book[1],sizeof(struct BookList),1,fp);
    fclose(fp);
    printf("\n您已成功向图书馆添加图书《%s》\n",Book[1].name);
    second();
}

void Booking()//预约图书
{
    FILE *fp;
    char bookname[40];
    int i,j,w,flag=0;
    printf(" 预约图书\n");
    printf("\n请输入图书名:");
    scanf("%s",bookname);
    fp=fopen("books_list.txt","rb");
    if(fp==NULL)
    {
        printf("\n无法打开该文件! ");
        return;
    }
    else
        for(w=0;w<1000;w++)
        {fread(&Book[w],sizeof(struct BookList),1,fp);
        }
        fclose(fp);
        for(i=0;i<1000;i++)
        {
            if(strcmp(Book[i].name,bookname)==0)
            {
                flag=1;
                if(Book[i].okay==1)
                {
                    if(Book[i].yes==1)//0,已被预约;1,可借出或预约;2,已被预约
                    {
                        //getch();
                        printf("\n");
                        strcpy(Book[i].ordername,Student->name);
                        Book[i].yes=2;
                        
                        fp=fopen("books_list.txt","wb");
                        for(j=0;j<1000;j++)
                            fwrite(&Book[j],sizeof(struct BookList),1,fp);
                        fclose(fp);
                        printf("\n预约图书成功!\n*预约期限为一个月!\n*");
                        second();
                    }
                    else
                    {
                        printf("\n该书已被借出或已被预约\n");
                        second();
                    }
                }
                else
                {
                    printf("该书已遗损!");
                    second();
                }
            }
        }
        if(!flag)
        {
            printf("该书不存在!\n");
            second();
        }
}
搜索更多相关主题的帖子: include int struct 
2008-06-26 09:19
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2008-06-26 09:26
li0605020322
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-6-23
收藏
得分:0 
哎,,怎么就没人给我个答案呢?哪位前辈指点指点啊?小弟在次多谢了啊!
2008-06-26 09:30
冰镇柠檬汁儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:北京
等 级:版主
威 望:120
帖 子:8078
专家分:6657
注 册:2005-11-7
收藏
得分:0 
这么多代码你要别人怎么看??
你有这个耐心写出来,为什么没这个耐心说明是什么问题??

本来无一物,何处惹尘埃
It is empty at all here, Why pm 2.5 is so TMD high!
2008-06-26 09:34
bianchengfeng
Rank: 1
等 级:新手上路
帖 子:79
专家分:0
注 册:2008-3-1
收藏
得分:0 
看了就晕倒了.....
2008-06-26 09:39
bianchengfeng
Rank: 1
等 级:新手上路
帖 子:79
专家分:0
注 册:2008-3-1
收藏
得分:0 
以前有过类似的帖子
建议在论坛里面找找
自己看...
2008-06-26 09:40
快速回复:急急!各位大虾帮帮忙啊!程序运行的时候有点问题!
数据加载中...
 
   



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

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