C语言结构体数组遍历

dag617712 2015-07-27 09:34:10
我需要遍历完整个数组后,输出符合条件的那一个,可是else多输出了,请问红色字体应如何修改?

struct Name
{
const int Base_Class1;
const int Sub_Class1;
const int Interface1;
const char *Meaning1;
};

struct Name mean[17]={
{0x00,0x00,0x00,"All currently implemented devices"},
{0x00,0x01,0x00,"VGA-compatible device"},
{0x01,0x01,0x80,"IDE controller"},
{0x01,0x80,0x00,"Other mass storage controller"},
{0x02,0x00,0x00,"Ethernet controller"},
{0x02,0x80,0x00,"Other network controller"},
{0x03,0x00,0x00,"VGA-compatible controller"},
{0x03,0x80,0x00,"Other display controller"},
{0x06,0x00,0x00,"Host bridge"},
{0x06,0x01,0x00,"ISA bridge"},
{0x06,0x04,0x00,"PCI-to-PCI bridge"},
{0x06,0x04,0x01,"Subtractive Decode PCI-to-PCI bridge"},
{0x06,0x07,0x00,"CardBus bridge"},
{0x0c,0x00,0x10,"IEEE 1394 OpenHCI"},
{0x0c,0x03,0x00,"USB Universal Host Controller"},
{0x0c,0x03,0x20,"Intel USB2 Enhanced Host Controller"},
{0x0c,0x05,0x00,"SMBus"},
};

for(i=0;i<17;i++)
{
if(Base_Class == mean[i].Base_Class1 && Sub_Class == mean[i].Sub_Class1 && Interface == mean[i].Interface1)
puts(mean[i].Meaning1);


else printf("%s\t","Unknow Device");

...全文
617 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-07-27
  • 打赏
  • 举报
回复
struct Name {
    const int Base_Class1;
    const int  Sub_Class1;
    const int  Interface1;
    const char  *Meaning1;
} mean[17]={
    {0x00,0x00,0x00,"All currently implemented devices"},
    {0x00,0x01,0x00,"VGA-compatible device"},
    {0x01,0x01,0x80,"IDE controller"},
    {0x01,0x80,0x00,"Other mass storage controller"},
    {0x02,0x00,0x00,"Ethernet controller"},
    {0x02,0x80,0x00,"Other network controller"},
    {0x03,0x00,0x00,"VGA-compatible controller"},
    {0x03,0x80,0x00,"Other display controller"},
    {0x06,0x00,0x00,"Host bridge"},
    {0x06,0x01,0x00,"ISA bridge"},
    {0x06,0x04,0x00,"PCI-to-PCI bridge"},
    {0x06,0x04,0x01,"Subtractive Decode PCI-to-PCI bridge"},
    {0x06,0x07,0x00,"CardBus bridge"},
    {0x0c,0x00,0x10,"IEEE 1394 OpenHCI"},
    {0x0c,0x03,0x00,"USB Universal Host Controller"},
    {0x0c,0x03,0x20,"Intel USB2 Enhanced Host Controller"},
    {0x0c,0x05,0x00,"SMBus"},
};
int i;
for (i=0;i<17;i++)
    if (Base_Class == mean[i].Base_Class1
     &&  Sub_Class == mean[i]. Sub_Class1
     &&  Interface == mean[i]. Interface1) break;
if (i<17) puts(mean[i].Meaning1);
else printf("%s\t","Unknow Device");
lin5161678 2015-07-27
  • 打赏
  • 举报
回复
for(i=0;i<17;i++)
{
    if(Base_Class == mean[i].Base_Class1 && Sub_Class == mean[i].Sub_Class1 && Interface == mean[i].Interface1)
    {
        puts(mean[i].Meaning1);
        break;
    }
}
if(i == 17)
    printf("%s\t","Unknow Device");
dag617712 2015-07-27
  • 打赏
  • 举报
回复
这不对吧?不知道你理解我程序想做什么么?
king191923157 2015-07-27
  • 打赏
  • 举报
回复
BOOL bl =flase; for() { if(true) { bl = true; break; } } if(!bl) {printf(); }

69,381

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧