首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

怎么在结构体数组中寻找合适的元素

2012-02-04 
如何在结构体数组中寻找合适的元素?这段程序想在结构体数组中选取合适的元素并利用,通过编译,但是运行时在

如何在结构体数组中寻找合适的元素?
这段程序想在结构体数组中选取合适的元素并利用,通过编译,但是运行时在输入第一组信息以后屏幕就不动了,错在哪里了?
这种选取元素的方法对吗?

#include "stdio.h "
#include "bios.h "
#include "stdlib.h "
struct   s
{
  char   name[10];
  int   price;
}list[]={{ "abc ",4},
                { "def ",3},
                { "ghi ",4}};

main()  
{
  char   name[10];
  int   amount,i=0,   price,key,j;
  for(i=0;;i++)
{
  printf( "input   the   ESC   to   quit,or   enter   any   other   key\n ");
  fflush(stdin);
  key=bioskey(0)&0xff;
  if((key&27)==27)
      break;
else
          {        
              printf( "please   input   the   No.%d   goods '   price   and   amount\n ",i+1);
              scanf( "%d%d ",list[i].name,amount);
              for(j=0;strcmp(name,list[i].name)!=0;j++)
              price=list[j].price*amount;
              printf( "%s*%d=%d ",list[j].name,amount,list[j].price);  
       
            }
}
}

[解决办法]
for(j=0;strcmp(name,list[i].name)!=0;j++)
这里死循环了

热点排行