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

哪位高手能帮忙看看这个程序那里出有关问题了?

2012-03-31 
谁能帮忙看看这个程序那里出问题了??main.cC/C++ code#includestdio.h#includestring.h#includestdli

谁能帮忙看看这个程序那里出问题了??
main.c

C/C++ code
#include<stdio.h>#include<string.h>#include<stdlib.h>#include"user.c"#include"cash_updata.c"#include"search.c"#define DATA_FILE "data_main.dat"cash *first_data=NULL;//整个程序中的财务数据头指针cash *get_last_cash(){    cash *p=first_data;    if(p==NULL)    {        return p;    }    while((p!=NULL)&&(p->next!=NULL))    {        p=p->next;    }    return p;}//获取指针中的最后一个。void init_cash(){    FILE* fp=NULL;    fp=fopen(DATA_FILE,"r");    if(fp==NULL)    {        fp=fopen(DATA_FILE,"w");        if(fp==NULL)        {            printf("新建财务数据保存文件失败,请按任意键退出...");            getchar();            exit(0);        }    }    fclose(fp);}//初始化财务数据保存的文件。void load_cash(){    cash *p=NULL;    cash *last=NULL;    FILE* fp=NULL;    int count =0;    p=(cash*)malloc(sizeof(cash));    p->next=NULL;    fp=fopen(DATA_FILE,"rb");    while(fread(&(p->all_about),sizeof(cash_data),1,fp)==1)    {        if(first_data==NULL)        {            first_data=p;        }        else        {            last=get_last_cash();//寻找尾指针            last->next=p;        }        count++;        fseek(fp,count*sizeof(cash_data),SEEK_SET);        p=(cash*)malloc(sizeof(cash));        p->next=NULL;    }    free(p);    p=NULL;    fclose(fp);}//读取财务数据,并且形成链表//VVVVVV============以下为菜单部分================VVVVVVvoid menu_admin(){    int act;    printf("欢迎使用班级财务管理系统!您的身份为管理员!\n");    printf("================================================\n");    printf("==============******管理菜单******==============\n");    printf("====================用户管理====================\n");    printf("==              1.浏览班级成员信息            ==\n");    printf("==              2.新建班级成员信息            ==\n");    printf("==              3.修改班级成员信息            ==\n");    printf("==              4.删除班级成员信息            ==\n");    printf("================================================\n");    printf("\n\n");    printf("================================================\n");    printf("====================财务管理====================\n");    printf("==              5.查询财务信息                ==\n");    printf("==              6.增加财务信息                ==\n");    printf("==              7.修改财务信息                ==\n");    printf("==              8.删除财务信息                ==\n");    printf("================================================\n");    printf("====================9.退出======================\n");    printf("================================================\n");    printf("请输入操作(1-9):");    scanf("%d",&act);    switch(act)    {/*    case 1:see_user();break;    case 2:add_user();break;    case 3:update_user();break;    case 4:delete_user();break;*/    case 5:see_cash();break;//完成    case 6:add_cash();break;//完成/*    case 7:update_cash();break;    case 8:delete_cash();break;*/    case 9:exit(0);    }}//管理员菜单void menu_user(){    int act;    printf("欢迎使用班级财务管理系统!您的身份为普通用户!\n");    printf("================================================\n");    printf("==============******查询菜单******==============\n");    printf("================================================\n");    printf("==              1.查询财务信息                ==\n");    printf("================================================\n");    printf("====================2.退出======================\n");    printf("================================================\n");    printf("请输入操作(1-2):");    scanf("%d",&act);    switch(act)    {    case 1:see_cash();break;//完成    case 2:exit(0);    }}//普通用户菜单void see_cash(){    int mark;    printf("================================================\n");    printf("==============******财务查询******==============\n");    printf("================================================\n");    printf("==                1.按年查询                  ==\n");    printf("==                2.按月查询                  ==\n");    printf("==                3.详细账单                  ==\n");    printf("================================================\n");    printf("================================================\n");    printf("==============******财务统计******==============\n");    printf("================================================\n");    printf("==              4.学期财务统计                ==\n");    printf("==              5.每月财务统计                ==\n");    printf("==              6.用途分类统计                ==\n");    printf("================================================\n");    printf("====================7.退出======================\n");    printf("================================================\n");    printf("请输入操作选项(1-7):");    scanf("%d",&mark);    switch(mark)    {    case 1:see_year();break;//完成    case 2:see_month();break;////完成    case 3:see_all();break;//完成/*    case 4:see_term();break;*/    case 5:see_month_all();break;//完成    case 6:see_use();break;//完成    case 7:exit(0);    }}//^^^^^^^^^================以上为菜单部分==========^^^^^int main(){    int id_in,te;    init_user();    load_user();    init_cash();    load_cash();    id_in=login_user();    if(id_in==5)exit(0);    if(id_in==1)    {        menu_admin();    }    if(id_in==0)    {        menu_user();    }}



search.c

C/C++ code
#include<stdio.h>#include<string.h>#include<stdlib.h>#include"data.h"//VVVVVVVVV============以下为查询函数===========VVVVVVVVVVvoid see_year(){    int mark;    cash *p=NULL;    cash_data year_mark_in,year_mark_out;    year_mark_in.use_all=0;    year_mark_out.use_all=0;    printf("请输入你要查询的年份(数字):");    scanf("%d",&mark);    p=first_data;    while(p!=NULL)    {        if(p->all_about.year==mark)        {            if(p->all_about.inorout==1)                year_mark_in.use_all+=p->all_about.use_all;            else                year_mark_out.use_all+=p->all_about.use_all;        }        p=p->next;    }    printf("%d年收支状况:",mark);    printf("收入:%d 元",year_mark_in.use_all);    printf("支出:%d 元",year_mark_out.use_all);}//年份查询函数void see_month(){    int mark,markm;    cash *p=NULL;    cash_data year_mark_in,year_mark_out;    year_mark_in.use_all=0;    year_mark_out.use_all=0;    printf("请输入你要查询的年份(数字):");    scanf("%d",&mark);    printf("请输入你要查询的月份(数字):");    scanf("%d",&markm);    p=first_data;    while(p!=NULL)    {        if((p->all_about.year==mark)&&(p->all_about.month==markm))        {            if(p->all_about.inorout==1)                year_mark_in.use_all+=p->all_about.use_all;            else                year_mark_out.use_all+=p->all_about.use_all;        }        p=p->next;    }    printf("%d年%d月收支状况:",mark,markm);    printf("收入:%d 元",year_mark_in.use_all);    printf("支出:%d 元",year_mark_out.use_all);}//按月份查询函数void see_all(){    cash *p=first_data;    int count;    count=0;    printf("=====全部财务报表======\n");    printf("=======================\n");    while(p!=NULL)    {        printf("%d -----\n",++count);        printf("时间:%d年%d月\n",p->all_about.year,p->all_about.month);        if(p->all_about.inorout==1)printf("收入:%d 元\n",p->all_about.use_all);            else printf("支出:%d 元\n",p->all_about.use_all);        switch(p->all_about.use_way)        {        case 1:printf("费用用途:活动娱乐消费\n");        case 2:printf("费用用途:工具/书籍经费\n");        case 3:printf("费用用途:临时消费\n");        case 4:printf("费用用途:定期费用\n");        }        printf("使用人:%s\n",use_who);        p=p->next;    }}//全部输出函数void see_use(){    cash *p=first_data;    cash_data mark_a,mark_b,mark_c,mark_d;    mark_a.year=0;    mark_a.month=0;    mark_b.year=0;    mark_b.month=0;    mark_c.year=0;    mark_c.month=0;    mark_d.year=0;    mark_d.month=0;    while(p!=NULL)    {        if(p->all_about.use_way==1)        {            if(p->all_about.inorout==1)            {                mark_a.year+=p->all_about.use_all;            }            else            {                mark_a.month+=p->all_about.use_all;            }        }//用途1        if(p->all_about.use_way==2)        {            if(p->all_about.inorout==1)            {                mark_b.year+=p->all_about.use_all;            }            else            {                mark_b.month+=p->all_about.use_all;            }        }//用途2        if(p->all_about.use_way==3)        {            if(p->all_about.inorout==1)            {                mark_c.year+=p->all_about.use_all;            }            else            {                mark_c.month+=p->all_about.use_all;            }        }//用途3                                                if(p->all_about.use_way==4)        {            if(p->all_about.inorout==1)            {                mark_d.year+=p->all_about.use_all;            }            else            {                mark_d.month+=p->all_about.use_all;            }        }//用途4        p=p->next;    }    printf("活动娱乐消费收支:\n");    printf("收入:%d 元\n",mark_a.year);    printf("支出:%d 元\n",mark_a.month);    printf("========================\n");    printf("工具/书籍经费收支:\n");    printf("收入:%d 元\n",mark_b.year);    printf("支出:%d 元\n",mark_b.month);    printf("========================\n");    printf("临时消费收支:\n");    printf("收入:%d 元\n",mark_c.year);    printf("支出:%d 元\n",mark_c.month);    printf("========================\n");    printf("定期费用收支:\n");    printf("收入:%d 元\n",mark_d.year);    printf("支出:%d 元\n",mark_d.month);    printf("========================\n");}//用途分类统计void see_month_all(){    cash *p=first_data;    cash_data mark;    int i;    for(i=1;i<=12;i++)    {        mark.year=0;        mark.month=0;        while(p!=NULL)        {        if(p->all_about.month==i)        {            if(p->all_about.inorout==1)            {   mark.year+=p->all_about.use_all;            }            else            {                mark.month+=p->all_about.use_all;            }        }        p=p->next;        }        printf("%d月收支:\n",i);        printf("收入:%d 元\n",mark.year);        printf("支出:%d 元\n",mark.month);        printf("================\n");        p=first_data;    }}//每月财务统计//^^^^^^^^^================以上为查询函数==========^^^^^


[解决办法]
偶遇到类似问题都是用
“每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。”
的方法解决的。

在每个最后不带\n的printf后面加fflush(stdout);
在每个不想受接收缓冲区旧内容影响的scanf前面加rewind(stdin);
另外请检查scanf的返回值。

热点排行