| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 356 人关注过本帖
标题:编程运行时出现先乱码现象,怎么解决?
只看楼主 加入收藏
woai_3554556
Rank: 1
来 自:湖北
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-3-16
结帖率:0
收藏
已结贴  问题点数:20 回复次数:3 
编程运行时出现先乱码现象,怎么解决?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
struct drug{
    char dno[11]; //编号
    char name[20];//名称
    char price[11];//单价
    char date[21];//生产日期
    char period[21];//保质期
};
struct drug drugs[1000];
int drugnum;

struct entry{
    char eno[10];
    char ename[20];
    char edate[21];
    char eamount[20]
} entrys[1000];
int entrynum;

struct chuku{
    char cno[11];
    char cname[20];
    int cdate[21];
    char camount[20];
} chukus[1000];
int chukunum;

void drug_input()
{
    struct drug d;
    int i;
    system("CLS");
    do {
        printf("请输入药品编号:");
        gets(d.dno);
        for(i=0;i<drugnum;i++)
            if (strcmp(drugs[i].dno,d.dno)==0)
                  {
                   printf("已经有该编号药品的信息\n");
                   continue;
                  }
      break;
   while(1);
    printf("请输入药品名称:");
    gets(d.name);
    printf("请输入药品单价:");
    gets(d.price);
    printf("请输入生产日期:");
    gets(d.date);
    printf("请输入保质期:");
    gets(d.period);
    drugs[drugnum++]=d;
}
while(1);
}
void drug_display()
{
int i ,drugnum ;
system("cls");
printf("编号   名称  单价   生产日期    保质期");
for(i=0;i<drugnum;i++)
printf("\n%10s %10s %10s %10s %10s",drugs[i].dno,drugs[i].name,drugs[i].price ,drugs[i].date,drugs[i].period);
printf("\n\n按任意键继续......");
getch();
}
void drug_info()
{
    int choice=1;
    while (choice)
        {
        system("CLS");
        printf("\n\n         ***药品目录管理***       \n\n");
        printf("\n\n             1.药品录入               ");
        printf("\n\n             2.药品修改               ");
        printf("\n\n             3.药品删除               ");
        printf("\n\n             4.药品查询               ");
        printf("\n\n             0.返回                   ");
        printf("\n\n            :)请输入你的选择:        ");
        scanf("%d",&choice);
        fflush(stdin);
        switch (choice)
            {
            case 1: drug_input();break;
            case 2: ;break;
            case 3: ;break;
            case 4: drug_display();break;
            }
        }

}

void entry_input()
{
    struct entry e;
    int i;
    system("CLS");
    do {
        printf("请输入药品编号:");
        gets(e.eno);
        for(i=0;i<entrynum
        ;i++)
            if (strcmp(entrys[i].eno,e.eno)==0)
                  {
                   printf("已经有该药品的信息\n");
                   continue;
                  }
        break;
    } while(1);
    printf("请输入药品名称:");
    gets(e.ename);
    printf("请输入入库时间:");
    gets(e.edate);
    printf("请输入入库数量:");
    gets(e.eamount);
    entrys[entrynum++]=e;
}

void entry_display()
{
int i;
system("cls");
printf("药品编号   药品名称   入库时间   入库数量   ");
for(i=0;i<entrynum;i++)
    printf("\n%10s %10s %10s %10s",entrys[i].eno,entrys[i].ename,entrys[i].edate,entrys[i].eamount);
printf("\n\n按任意键继续......");
getch();
}

void entry_info()
{
   int choice=1;
    while (choice)
        {
        system("CLS");
        printf("\n\n           ***入库单的管理***\n\n");
        printf("\n\n               1.药品录入        ");
        printf("\n\n               2.药品修改        ");
        printf("\n\n               3.药品删除        ");
        printf("\n\n               4.药品查询        ");
        printf("\n\n               0.返回            ");
        printf("\n\n              :)请输入你的选择: ");
        scanf("%d",&choice);
        fflush(stdin);
        switch (choice)
            {
            case 1: entry_input();break;
            case 2: ;break;
            case 3: ;break;
            case 4: entry_display();break;
            }
        }
}
void chuku_input()
{
    struct chuku c;
    int i;
    system("CLS");
    do {
        printf("请输入药品编号:");
        gets();
        for(i=0;i<chukunum
        ;i++)
            if (strcmp(chukus[i].cno,)==0)
                  {
                   printf("已经有该药品的信息\n");
                   continue;
                  }
        break;
    } while(1);
    printf("请输入药品名称:");
    gets();
    printf("请输入出库时间:");
    gets(c.cdate);
    printf("请输入出库数量:");
    gets(c.camount);
    chukus[chukunum++]=c;
}

void chuku_display()
{
int i;
system("cls");
printf("    药品编号    药品名称     出库时间    出库数量   ");
for(i=0;i<chukunum;i++)
    printf("\n%10s %10s %10s %10s ",chukus[i].cno,chukus[i].cname,chukus[i].cdate,chukus[i].camount);
printf("\n\n按任意键继续......");
getch();
}

void chuku_info()
{
   int choice=1;
    while (choice)
        {
        system("CLS");
        printf("\n\n       ***出库单的管理***\n\n  ");
        printf("\n\n          1.药品录入           ");
        printf("\n\n          2.药品修改           ");
        printf("\n\n          3.药品删除           ");
        printf("\n\n          4.药品查询           ");
        printf("\n\n          0.返回               ");
        printf("\n\n        :)请输入你的选择:     ");
        scanf("%d",&choice);
        fflush(stdin);
        switch (choice)
            {
            case 1: chuku_input();break;
            case 2: ;break;
            case 3: ;break;
            case 4: chuku_display();break;
            }
        }
}
void search()
{
    int choice=1;
    while(choice)
       {
    system("CLS");
    printf("\n\n         ***药品信息查询***  \n\n");
    printf("\n\n            1.药品基本信息       ");
    printf("\n\n            2.药品入库信息       ");
    printf("\n\n            3.药品出库信息       ");
    printf("\n\n            0.返回               ");
    printf("\n\n         :)请输入你的选择:      ");
    scanf("%d",&choice);
    fflush(stdin);
        switch (choice)
            {
            case 1: break;
            case 2: ;break;
            case 3: ;break;
            case 4: break;
            }
       }
}
int main()
{
    FILE *fp1,*fp2,*fp3;
    int choice=1;
    if ((fp1=fopen("drug.dat","r"))!=NULL)
        while (fread(&drugs[drugnum],1,sizeof(struct drug),fp1))
            drugnum++;
    if ((fp2=fopen("entry.dat","r"))!=NULL)
        while (fread(&entrys[entrynum],1,sizeof(struct entry),fp2))
            entrynum++;
    if ((fp3=fopen("chuku.dat","r"))!=NULL)
        while (fread(&chukus[chukunum],1,sizeof(struct chuku),fp3))
            chukunum++;

    while (choice)
        {
        system("CLS");
         printf("\n\n             ~~~~~~欢迎进入药房药品管理系统~~~~~~        \n\n");
         printf("\n\n                       1.药品目录管理                        ");
         printf("\n\n                       2.入库单的管理                        ");
         printf("\n\n                       3.出库单的管理                        ");
         printf("\n\n                       4.药品信息查询                        ");
         printf("\n\n                       0.结束                                ");
         printf("\n\n                    :)请输入你的选择:                       ");
         scanf("%d",&choice);
         fflush(stdin);
        switch (choice)
            {
            case 1: drug_info();break;
            case 2: entry_info();break;
            case 3: chuku_info();break;
            case 4: search();break;
            }

        }
    fp1=fopen("drug.dat","w");
    fwrite(&drugs[0],sizeof(struct drug),drugnum,fp1);
    fp2=fopen("entry.dat","w");
    fwrite(&entrys[0],sizeof(struct entry),entrynum,fp2);
    fp3=fopen("chuku.dat","w");
    fwrite(&chukus[0],sizeof(struct chuku),chukunum,fp3);
    return 0;
}
搜索更多相关主题的帖子: include period 保质期 price 
2014-03-16 15:04
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:7 
大长了  分模块调式  都调好后再拼接

DO IT YOURSELF !
2014-03-16 23:16
韶志
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:斗气大陆
等 级:贵宾
威 望:44
帖 子:2223
专家分:13592
注 册:2013-3-22
收藏
得分:7 
原因不清...
可能是你输出地址或输出内容为空的变量

设置断点调试吧

三十年河东,三十年河西,莫欺少年穷!
2014-03-17 13:36
fragileeye
Rank: 5Rank: 5
等 级:职业侠客
威 望:2
帖 子:107
专家分:387
注 册:2011-5-21
收藏
得分:7 
无图无真相、说清楚你的问题。
2014-03-20 12:46
快速回复:编程运行时出现先乱码现象,怎么解决?
数据加载中...
 
   



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

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