标题:想把下面的程序改为指针类型
只看楼主
yulin959
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-8-29
结帖率:0
已结贴  问题点数:20 回复次数:5 
想把下面的程序改为指针类型
                        
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct shangpin
{
    char name[20];/*商品名称*/
    char bianhao[20];/*商品编号*/
    char number[20];/*商品数量*/
    char producedate[20];/*商品生产日期*/
    char deaddate[20];/*食品保质期*/
};
struct shangpin sha[6]={
    {"洗衣服","111","200","2012.06.07","1"},
    {"方便面","112","100","2012.02.11","1"},
    {"冰红茶","113","50","2012.01.05","2"},
    {"火腿肠","114","70","2012.11.03","1"},
    {"红糖","115","20","2012.05.14","2"},
    {"果冻","116","30","2012.10.03","1"}
};
int num=6;
void cha_1 ();
void cha_2 ();
void cha ();
void shu ();
void gai ();
void gai_1 ();
void gai_2 ();
void gai_2_1 ();
void gai_2_2 ();
void zhu ();
void cha ()
{
    int i;
    printf ("\t\t1按名称查询\n");
    printf ("\t\t2按编号查询\n");
    printf ("\n\n请按你的需要选择你所需要的服务:\n");
    scanf ("%d",&i);
    switch (i)
    {
    case 1:
        {
            cha_1();
            break;
        }
    case 2:
        {
            cha_2();
            break;
        }
    }
}
void cha_1 ()//按名称查询
{
    int i,k;
    char name[20];
    printf ("请输入商品名称:\n");  
    scanf ("%s",name);
    for (i=0;i<num;i++)
    {
        if (strcmp(sha[i].name,name)==0)
            printf ("%s\t%s\t%s\t%s\t%s",sha[i].name,sha[i].bianhao,sha[i].number,sha[i].producedate,sha[i].deaddate);
    }
    printf ("是否继续查询(1是0否)\n");
    scanf ("%d",&k);
    if (k==1)
        cha ();
    else
        zhu ();
}
void cha_2 ()
{
    int i,k;
    char bianhao[20];
    printf ("请输入商品编号:\n");
    scanf ("%s",bianhao);
    for (i=0;i<num;i++)
    {
        if (strcmp(sha[i].bianhao,bianhao)==0)
            printf ("%s\t%s\t%s\t%s\t%s\n",sha[i].name,sha[i].bianhao,sha[i].number,sha[i].producedate,sha[i].deaddate);
    }
    printf ("是否继续查询(1是0否)");
    scanf ("%d",&k);
    if (k==1)
        cha ();
    else
        zhu ();
}
void shu ()
{
    int i;
    char k;
    for (i=0;i<num;i++)
    {
        printf ("%s\t\t%s\t\t%s\t\t%s\t\t%s\n",sha[i].name,sha[i].bianhao,sha[i].number,sha[i].producedate,sha[i].deaddate);
    }
    printf ("按任意键返回主菜单\n");
    scanf ("%s",&k);
    zhu ();
}
void gai ()
{
    int i;
    printf ("\t\t1.商品添加\n");
    printf ("\t\t2.商品删除\n\n");
    printf ("请按你的需要选择适当的服务:\n");
    scanf ("%d",&i);
    switch (i)
    {
    case 1:
        {
            gai_1 ();
            break;
        }
    case 2:
        {
            gai_2 ();break;
        }
    }
}
void gai_1 ()//商品添加
{
    int i,k;
    for (i=num;i<=200;i++)
    {
        printf ("请输入商品名称\n");
        scanf ("%s",&sha[i].name);
        printf ("请输入商品编号\n");
        scanf ("%s",&sha[i].bianhao);
        printf ("请输入商品数量\n");
        scanf ("%s",&sha[i].number);
        printf ("请输入商品生产日期\n");
        scanf ("%s",&sha[i].producedate);
        printf ("请输入商品保质日期\n");
        scanf ("%s",&sha[i].deaddate);
        num++;
        printf ("\n\n是否继续添加(1是0否)\n");
        scanf ("%d",&k);
        if (k==1)
        printf ("*******************************************");
        else
            break;
    }
}
void gai_2 ()//商品删除
{
    int i;
    printf ("\t\t1.按名称删除\n");
    printf ("\t\t2.按编号删除\n\n");
    printf ("请按你的需要选择适当的服务:\n");
    scanf ("%d",&i);
    switch (i)
    {
    case 1:
        {
            gai_2_1 ();
            break;
        }
    case 2:
        {
            gai_2_1 ();
            break;
        }
    }
}
void gai_2_1 ()//按名称删除
{
    int i,k;
    char name[20];
    for (i=0;i<num;i++)
    {
        printf ("请输入商品名称:\n");
        if (strcmp(sha[i].name,name)==0)
        {
            printf ("%s\t%s\t%s\t%s\t%s\n",sha[i].name,sha[i].bianhao,sha[i].number,sha[i].producedate,sha[i].deaddate);
        }
        printf ("是否删除(1是0否)");
        scanf ("%d",&k);
            if (k==1)
            {
                sha[i]=sha[i+1];
                num--;
                printf ("******************************************************");
            }
            else
                break;
    }
    printf ("是否继续删除(1是0否)");
    scanf ("%d",&k);
    if (k==1)
        gai ();
    else
        zhu ();
}
void gai_2_2()//按编号删除
{
    int i,k;
    char bianhao[20];
    for (i=0;i<num;i++)
    {
        printf ("请输入商品编号:\n");
        scanf("%s",bianhao);
        if (strcmp(sha[i].bianhao,bianhao)==0)
        {
            printf ("%s\t%s\t%s\t%s\t%s\n",sha[i].name,sha[i].bianhao,sha[i].number,sha[i].producedate,sha[i].deaddate);
        }
        printf ("是否删除(1是0否)\n");
        scanf ("%d",&k);
            if (k==1)
            {
                sha[i]=sha[i+1];
                num--;
    printf("***********************************");
            }
            else
                break;
    }
    printf ("是否继续添加(1是0否)\n");
    scanf ("%d",&k);
    if (k==1)
        gai ();
    else
        zhu ();
}
void zhu ()
{
    int i;
    system ("cls");
    printf ("\n\n\n\n\n");
    printf("\t\t欢迎进入商店管理系统\n");
    printf("************************************************\n");
    printf("************************************************\n");
    printf ("\t\t1.商品查询\t\t\t\n");
    printf ("\t\t2.商品输出\t\t\t\n");
    printf ("\t\t3.商品修改\t\t\t\n");
    printf ("***********************************************\n");
    printf("************************************************\n");
    printf("请输入你所需要的服务,谢谢!\n");
    scanf ("%d",&i);
    switch (i)
    {
    case 1:
        {
            cha ();
            break;
        }
    case 2:
        {
            shu ();
            break;
        }
    case 3:
        {
            gai ();
            break;
        }
    case 4:
        break;
    }
}
void main ()
{
    zhu ();
}


 
搜索更多相关主题的帖子: 商品 冰红茶 include number 火腿肠 
2012-08-29 21:38
embed_xuel
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
等 级:贵宾
威 望:58
帖 子:3845
专家分:11385
注 册:2011-9-13
得分:4 
莫名其妙

总有那身价贱的人给作业贴回复完整的代码
2012-08-29 22:08
TonyDeng
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:304
帖 子:25859
专家分:48889
注 册:2011-6-22
得分:4 
以下是引用embed_xuel在2012-8-29 22:08:00的发言:

莫名其妙

看到标题都不想点进来啦,你还回帖。

授人以渔,不授人以鱼。
2012-08-29 22:30
姻脂梦
Rank: 6Rank: 6
等 级:侠之大者
帖 子:264
专家分:424
注 册:2012-7-3
得分:4 
就是,你还进来回帖?
2012-08-30 00:21
netlin
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:24
帖 子:544
专家分:4308
注 册:2012-4-9
得分:4 
路过!

做自己喜欢的事!
2012-09-02 08:24
菜鸟7号
Rank: 2
等 级:论坛游民
帖 子:21
专家分:17
注 册:2011-8-29
得分:4 
太长了..
2012-09-02 21:17



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




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

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