想给一下下面程序。把它改为指针类型
#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 ();
}