搜索
查看: 1433|回复: 1
打印 上一主题 下一主题

求助,语法问题,谢谢

[复制链接]
跳转到指定楼层
楼主
发表于 2013-6-27 23:54:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
5啊哈币
源代码是这样子的:
#include "stdio.h"
#include "Conio.h"
#include"process.h"
#define NULL 0
#define namelen 10

/*定义商品结构体*/
struct GOODS
{
   int id,day;
   char price[20];
   char name[20];
   char count[20];
   char number[20];
   char code[20];
};

/*声明商品数组及商品数量*/
struct GOODS goods[100];

/*输入商品信息*/
void GOODS_input()
{
        int x=0;

     while(1)
     {
         printf("请输入编号:");
         scanf("%d",&goods[x].id);
         getchar();

         printf("请输入名称:");
         scanf("%s",&goods[x].name);
         getchar();

         printf("请输入价格:");
         scanf("%s",&goods[x].price);
         getchar();

         printf("请输入条形码:");
         scanf("%d",&goods[x].code);
         getchar();
                 
                 printf("请输入进货日期:");
         scanf("%d",&goods[x].day);
         getchar();

             printf("请输入库存:");
         scanf("%d",&goods[x].number);
         getchar();
                 
                 printf("请输入销售数量:");
         scanf("%d",&goods[x].count);
         getchar();

    FILE *fp;

     fp=fopen("GOODS.txt","a");

      fwrite(&goods[x],sizeof(struct GOODS),1,fp);
      fclose(fp);
         x++;

         printf("是否继续(y/n)?:\n");
        if(getchar()=='n')
        {
               break;
        }
     }
}

/*显示商品信息*/
void GOODS_output()
{
     int y;
         FILE *fp;
         fp=fopen("GOODS.txt","r");
     printf("%10s%10s%10s%10s%10s%10s%10s\n","编号","名称","价格","条形码","进货日期","库存","销售数量");
     printf("*******************************************************\n");
         for (y=0;fread(&goods[y],sizeof(struct GOODS),1,fp)!=0;y++)
     {
        printf("%10d%10s%10s%10s%10s%10s%10s\n",goods[y].id,goods[y].name,goods[y].price,goods[y].code,goods[y].day,goods[y].number,goods[y].count);
     }
}


/*通过编号返回数组下标*/
int GOODS_id(int id)
{
     int z;
     for (z=0;z<100;z++)
     {
         if (goods[z].ID==id)
         {
              return z;
         }
     }
     return -1;
}


/*显示单条商品记录*/
void GOODS_one(int one)
{
        int i;
    i=one;
        printf("%10s%10s%10s%10s%10s%10s%10s\n","编号","名称","价格","条形码","进货日期","库存","销售数量");
         printf("*******************************************************\n");
         printf("%10d%10s%10s%10s%10s%10s%10s\n",goods[y].id,goods[y].name,goods[y].price,goods[y].code,goods[y].day,goods[y].number,goods[y].count);
}

/*排序函数*/
void GOODS_paixu()
{system("cls");
        int i,j;
struct goods good;
FILE *fp;
fp=fopen("GOODS.txt","rb");//以只读方式打开GOODS文件
for(j=0;j<n;j++)
fread(&GOODS[j],sizeof(struct goods),1,fp);
for(j=0;j<n;j++)
for(i=0;i<n-j;i++)
if(GOODS[i].sum<GOODS[i+1].sum)
{good=GOODS[i];
GOOdS[i]=GOOdS[i+1];
GOODS[i+1]=good;
}
printf("\n*******************************************\n");
printf("\t 编号   名称   价格");
printf("条形码    进货日期    库存    销售数量\n");
for(i=0;i<n;i++)
{printf("\t%s%d%d", goods[y].id,goods[y].name,goods[y].price);
printf("%d%d%d%d", goods[y].code,goods[y].day,goods[y].number,goods[y].count);
printf("\n");
}
printf("\n\t******************************************\n");
}

/*将商品信息写入文件*/
void GOODS_file()
{
     FILE *fp;
     int i;
     if ((fp=fopen("GOODS.txt","wb"))==NULL)
     {
         printf("不能打开文件!\n");
         return;
     }
     for (i=0;i<num;i++)
     {
         if (fwrite(&goods[i],sizeof(struct GOODS),1,fp)!=1)
         {
              printf("写入文件错误!\n");
         }
     }   
     fclose(fp);

}

/*主程序界面*/

void main()
{
     int choice,index;
     int Number=0;
while(1)
     {
         /*主菜单界面*/
         printf("\n\n");
         printf("*********** 超市信息管理系统***********\n");
         printf("            1. 输入商品名称            \n");
         printf("            2. 显示商品详细情况        \n");
         printf("            3. 查找商品                \n");
         printf("            4. 插入商品信息            \n");
         printf("            5.保存商品信息             \n");
         printf("            6.排序商品                 \n");
         printf("            7. 退出                    \n");
         printf("***************************************\n");
         printf("请选择(1-7):");
         scanf("%d",&choice);
         getchar();

       switch(choice)
         {
           case 1:
              GOODS_input();/*输入操作*/
              break;

          case 2:
              printf("请输入编号:");/*按编号查找*/
              scanf("%d",&Number);
              index=GOODS_id(Number); /*找出符合编号的信息*/
              GOODS_one(one);
              break;
           case 3:
              GOODS_output();/*显示商品信息*/
              break;
           case 4:
              GOODS_input();/*插入商品信息*/
              GOODS_output();
              break;
           case 5:
              GOODS_file();  /*保存信息到文件*/
           case 6:
              GOODS_paixu()  /*排序商品*/
           case 7:
              exit(0);  /*退出*/
         }

     }
getch();
}






错误信息如下:
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
C:\Users\CSDBY\Desktop\Cpp1.cpp(93) : error C2039: 'ID' : is not a member of 'GOODS'
        C:\Users\CSDBY\Desktop\Cpp1.cpp(9) : see declaration of 'GOODS'
C:\Users\CSDBY\Desktop\Cpp1.cpp(109) : error C2065: 'y' : undeclared identifier
C:\Users\CSDBY\Desktop\Cpp1.cpp(116) : error C2079: 'good' uses undefined struct 'goods'
C:\Users\CSDBY\Desktop\Cpp1.cpp(119) : error C2065: 'n' : undeclared identifier
C:\Users\CSDBY\Desktop\Cpp1.cpp(120) : error C2275: 'GOODS' : illegal use of this type as an expression
        C:\Users\CSDBY\Desktop\Cpp1.cpp(9) : see declaration of 'GOODS'
C:\Users\CSDBY\Desktop\Cpp1.cpp(120) : error C2027: use of undefined type 'goods'
        C:\Users\CSDBY\Desktop\Cpp1.cpp(116) : see declaration of 'goods'
C:\Users\CSDBY\Desktop\Cpp1.cpp(123) : error C2143: syntax error : missing ')' before '['
C:\Users\CSDBY\Desktop\Cpp1.cpp(123) : error C2143: syntax error : missing ';' before '['
C:\Users\CSDBY\Desktop\Cpp1.cpp(123) : error C2059: syntax error : ')'
C:\Users\CSDBY\Desktop\Cpp1.cpp(124) : error C2143: syntax error : missing ';' before '{'
C:\Users\CSDBY\Desktop\Cpp1.cpp(124) : error C2275: 'GOODS' : illegal use of this type as an expression
        C:\Users\CSDBY\Desktop\Cpp1.cpp(9) : see declaration of 'GOODS'
C:\Users\CSDBY\Desktop\Cpp1.cpp(125) : error C2065: 'GOOdS' : undeclared identifier
C:\Users\CSDBY\Desktop\Cpp1.cpp(125) : error C2109: subscript requires array or pointer type
C:\Users\CSDBY\Desktop\Cpp1.cpp(125) : error C2109: subscript requires array or pointer type
C:\Users\CSDBY\Desktop\Cpp1.cpp(125) : error C2106: '=' : left operand must be l-value
C:\Users\CSDBY\Desktop\Cpp1.cpp(126) : error C2143: syntax error : missing ';' before '['
C:\Users\CSDBY\Desktop\Cpp1.cpp(126) : error C2143: syntax error : missing ';' before '['
C:\Users\CSDBY\Desktop\Cpp1.cpp(132) : error C2275: 'goods' : illegal use of this type as an expression
        C:\Users\CSDBY\Desktop\Cpp1.cpp(116) : see declaration of 'goods'
C:\Users\CSDBY\Desktop\Cpp1.cpp(132) : error C2228: left of '.id' must have class/struct/union type
C:\Users\CSDBY\Desktop\Cpp1.cpp(132) : error C2275: 'goods' : illegal use of this type as an expression
        C:\Users\CSDBY\Desktop\Cpp1.cpp(116) : see declaration of 'goods'
C:\Users\CSDBY\Desktop\Cpp1.cpp(132) : error C2228: left of '.name' must have class/struct/union type
C:\Users\CSDBY\Desktop\Cpp1.cpp(132) : error C2275: 'goods' : illegal use of this type as an expression
        C:\Users\CSDBY\Desktop\Cpp1.cpp(116) : see declaration of 'goods'
C:\Users\CSDBY\Desktop\Cpp1.cpp(132) : error C2228: left of '.price' must have class/struct/union type
C:\Users\CSDBY\Desktop\Cpp1.cpp(133) : error C2275: 'goods' : illegal use of this type as an expression
        C:\Users\CSDBY\Desktop\Cpp1.cpp(116) : see declaration of 'goods'
C:\Users\CSDBY\Desktop\Cpp1.cpp(133) : error C2228: left of '.code' must have class/struct/union type
C:\Users\CSDBY\Desktop\Cpp1.cpp(133) : error C2275: 'goods' : illegal use of this type as an expression
        C:\Users\CSDBY\Desktop\Cpp1.cpp(116) : see declaration of 'goods'
C:\Users\CSDBY\Desktop\Cpp1.cpp(133) : error C2228: left of '.day' must have class/struct/union type
C:\Users\CSDBY\Desktop\Cpp1.cpp(133) : error C2275: 'goods' : illegal use of this type as an expression
        C:\Users\CSDBY\Desktop\Cpp1.cpp(116) : see declaration of 'goods'
C:\Users\CSDBY\Desktop\Cpp1.cpp(133) : error C2228: left of '.number' must have class/struct/union type
C:\Users\CSDBY\Desktop\Cpp1.cpp(133) : error C2275: 'goods' : illegal use of this type as an expression
        C:\Users\CSDBY\Desktop\Cpp1.cpp(116) : see declaration of 'goods'
C:\Users\CSDBY\Desktop\Cpp1.cpp(133) : error C2228: left of '.count' must have class/struct/union type
C:\Users\CSDBY\Desktop\Cpp1.cpp(149) : error C2065: 'num' : undeclared identifier
C:\Users\CSDBY\Desktop\Cpp1.cpp(193) : error C2065: 'one' : undeclared identifier
C:\Users\CSDBY\Desktop\Cpp1.cpp(206) : error C2143: syntax error : missing ';' before 'case'
执行 cl.exe 时出错.

Cpp1.obj - 1 error(s), 0 warning(s)





求指导,我菜鸟啊






沙发
发表于 2013-6-28 00:25:27 | 只看该作者
本帖最后由 rosynirvana 于 2013-6-28 00:26 编辑

这错误提示不都挺明确的?
93行,没有ID这个成员,因为你定义的时候写的是id
109行,y未定义
116行,结构体goods未定义,因为你定义的时候写的是GOODS


此外这是VC6?从各种意义上都不建议用这种老古董
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

广播台
特别关注
快速回复 返回顶部 返回列表