标题:为什么运行不了啊
只看楼主
jay101767
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2019-3-28
结帖率:0
 问题点数:0 回复次数:0 
为什么运行不了啊

#include "stdafx.h"
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
#include"math.h"
#include"conio.h"
#define CHENGGONG 1
#define SHIBAI 0
#define SHOURU 1
#define ZHICHU 2
#define ZENGJIA 1
#define SHANCHU 2
#define XIUGAI 3
#define CHAXUN 4
#define TONGJI 5
#define TUICHU 6
#define LEN sizeof(struct shouzhixinxi)
struct shouzhixinxi
{
char xingming[20];
char laiyuan[40];
char riqi[20];
int shumu;
struct shouzhixinxi*next;
};
struct shouzhixinxi*head1=(struct shouzhixinxi*)malloc(LEN);
struct shouzhixinxi*head2;

char xuanze;
/*该数据用于接收选择信息*/
int tishi;
/*用于接收各函数返回的提示信息*/
int dijitiao=0;
/*用于表示当前是第几条信息*/
int i;
/*用于存放临时的条数,相当于零食的dijitiao*/
char linshi[40];
double linshi2;
/*用于存放一些临时信息*/
/*代码*/
/*用于保存信息*/



int shuchu(shouzhixinxi*p6)
{
printf("\n\n \37~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\37\n");
printf(" \23 \3.收 支 人 员 姓 名:%-20s\23\n",p6->xingming);
printf(" \23 \3.收 支 来 源 或 去 向:%-17s\23\n",p6->laiyuan);
printf(" \23 \3.收 支 日 期:%-26s\23\n",p6->riqi);
printf(" \23 \3.收 支 数 目:%-26s\23\n",p6->shumu);
printf(" \36~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\36\n");
return CHENGGONG;
}

void baocun(shouzhixinxi*p)
{
    FILE *fp;
    fp=fopen("shouzhiguanli.txt","w+");
    fprintf(fp,"%s ",p->xingming);
    fprintf(fp,"%s ",p->laiyuan);
    fprintf(fp,"%s ",p->riqi);
    fprintf(fp,"%d ",p->shumu);
    fclose(fp);
}

void xinzeng(shouzhixinxi*head)
{
    shouzhixinxi*p3,*p4;p4=(struct shouzhixinxi*)malloc(LEN);
    p3=head;
   
    while(1)
    {
        p4=(struct shouzhixinxi*)malloc(LEN);
        printf("\n请输入收入或支出人员的姓名:");
        scanf("%s",p3->xingming);
        printf("\n请输入收入来源或支出去向:");
        scanf("%s",p3->laiyuan);
        printf("\n请输入收入或支出的日期:");
        scanf("%s",p3->riqi);
        printf("\n请输入收入或支出的数目:");
        scanf("%d",p3->shumu);
        printf("是否保存这条信息? <Y/N>\n");
        xuanze=_getch();
        if(xuanze=='Y' || xuanze=='y')
            {
                baocun(p3);
                p3->next =p4;p3=p4;
                printf("保存成功\n");
            }
        printf("是否继续添加新记录? <Y/N>\n");
        xuanze=_getch();
        printf("\n");
        if(xuanze=='N' || xuanze=='n')
           {     
                p3->next=NULL;break;
           }
    }
}

void chaxun(void)
{
    struct shouzhixinxi*p5=head1;
    while(1)
   {
       printf("\n请选择查询方式: 1.姓名 2.来源或去向 3.日期 4.数目\n");
       xuanze=_getch();
      xuanze=xuanze-48;
        switch(xuanze)
      {
        case 1:
        printf("请输入要查询的姓名:");
        scanf("%s",linshi);
        for(;;p5=p5->next)                                                     
         {
             if(strcmp(p5->xingming,linshi)==0) /*查询*/
                 tishi=shuchu(p5);break;
        }
             if(tishi!=CHENGGONG  )            
             printf("未找到相关记录\n");  break;
        case 2:
        printf("请输入要查询的来源或去向:");
        scanf("%s",linshi);
        for(;;p5=p5->next)
        {
            if(strcmp(p5->laiyuan,linshi)==0) /*查询*/
                tishi=shuchu(p5);break;
        }
        if(tishi!=CHENGGONG)
        printf("未找到相关记录\n");break;
        case 3:
        printf("请输入要查询的日期:");
        scanf("%s",linshi);
        for(;;p5=p5->next)
        {
            if(strcmp(p5->riqi,linshi)==0) /*查询*/
                tishi=shuchu(p5);break;
        }
        if(tishi!=CHENGGONG)
        printf("未找到相关记录\n");break;
        case 4:
        printf("请输入要查询的数目:");
        scanf("%d",i);
        for(;;p5=p5->next)
        {
            if(p5->shumu==i)
                tishi=shuchu(p5);break;
        }
             if(tishi!=CHENGGONG)
             printf("未找到相关记录\n");break;
       default:printf("输入错误\n");
       }
        printf("是否继续查询? <Y/N>");
        xuanze=_getch();
        if(xuanze=='N' || xuanze=='n')
        {return;}
}
}
int daoruxinxi()
{
    struct shouzhixinxi*p1,*p2;
    FILE*fp;
    if((fp=fopen("shouzhiguanli.txt","r+"))==NULL)
    {
        printf("当前收支情况文件不存在.\n");
        if((fp=fopen("shouzhiguanli.txt","w+"))==NULL)
            {
               printf("未知错误导致未能建立新文件,按任意键结束程序.\n");
               _getch();
               exit(0);
            }
       else
           {
             printf("建立新文件成功,是否开始新建记录. <Y\\N>\n");
            xuanze=_getch();
            if(xuanze=='Y' || xuanze=='y')
            xinzeng(head1);
           }
    }
    else
    {
        head1=p1=(struct shouzhixinxi*)malloc(LEN);
        for(; !feof(fp);)
            {
                p2=(struct shouzhixinxi*)malloc(LEN);
                fscanf(fp,"%s ",p1->xingming);
                fscanf(fp,"%s ",p1->laiyuan);
                fscanf(fp,"%s ",p1->riqi);
                fscanf(fp,"%s ",p1->shumu);
               p1->next=p2;p1=p2;
            }
        p1->next=NULL;
        fclose(fp);
        return CHENGGONG;
    }
    return SHIBAI;
}



int _tmain(int argc, _TCHAR* argv[])
{
    if(daoruxinxi()==CHENGGONG)
        {
           int xunhuan=1; /*用于控制循环*/
          while(xunhuan)
        {
              printf("\n\n\n \37~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\37\n"); /*以下输出提示信息*/
              printf(" \23 导 入 收 支 情 况 成 功. \23\n");
              printf(" \23~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\23\n");
              printf(" \23 \1 1. 增 加 新 记 录 \23\n");
              printf(" \23 \1 2. 删 除 已 有 记 录 \23\n");
              printf(" \23 \1 3. 修 改 已 有 记 录 \23\n");
              printf(" \23 \1 4. 查 询 已 有 记 录 \23\n");
              printf(" \23 \1 5. 统 计 一 段 时 间 内 的 数 据 \23\n");
              printf(" \23 \1 6. 退 出 该 系 统 \23\n");
              printf(" \36~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\36\n\n");
              printf("请选择要执行的操作:");
              xuanze=_getch(); /*选择操作*/
              xuanze=xuanze-48; /*前面接收的是1的ASC码实际上是49而不是1,转换一下*/
              switch(xuanze)
               {
                  case ZENGJIA:xinzeng(head1);break;
   
   
                  case CHAXUN:chaxun();break;
                 
                  case TUICHU:xunhuan=0;break;
                 default:printf("输入错误.\n");
               }
         }
         }

    return 0;
}

搜索更多相关主题的帖子: define struct printf 输入 break 
2019-04-01 19:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-493902-1-1.html




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

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