Chinaunix首页 | 论坛 | 博客
  • 博客访问: 391661
  • 博文数量: 199
  • 博客积分: 154
  • 博客等级: 入伍新兵
  • 技术积分: 1530
  • 用 户 组: 普通用户
  • 注册时间: 2011-03-14 08:43
文章分类

全部博文(199)

文章存档

2015年(101)

2014年(97)

2011年(1)

分类: C/C++

2015-04-07 20:24:08

typedef struct student{
int id;                    /*学生编号*/
char name[10];      /*姓名*/
float score;            /*成绩*/
}Student;


int search(Student stu[],int n,int key){
int i;
for(i=0;i    if( stu[i].id == key )                      /*查找成功*/
       return i;     
return -1;                                       /*查找失败*/
}


void shunxu()
{    
    Student stu[4] = {{1004,"TOM",100},
                    {1002,"LILY",95},
{1001,"ANN",93},
{1003,"LUCY",98}
};                                /*初始化结构体数组*/
int addr;                       /*查找记录地址*/
addr = search(stu,4,1001);
printf("Student ID: %d\n",stu[addr].id);
printf("Student name: %s\n",stu[addr].name);
printf("Student score: %f\n",stu[addr].score);  
}

阅读(1059) | 评论(1) | 转发(0) |
1

上一篇:python之FAQ

下一篇:折半查找

给主人留下些什么吧!~~

wq41132015-04-07 20:25:31

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[])
{
  shunxu();
  system("PAUSE"); 
  return 0;
}