先准备好一个文件 hw.dat 包含所需要的信息。
(问:为什么是.dat文件呢,可以是.txt文件吗?答:1,.dat文件是书上说的,我也不懂;2.也可以是.txt文件,都可以打开,不确定就多试试。)
#include <stdio.h>
#define NAME_LEN 64
struct info{
char name[NAME_LEN];
double height;
double weight;
};//结构体
void swap_info(struct info *x,struct info *y)//交换两个结构体元素
{
struct info temp;
temp=*x;
*x=*y;
*y=temp;
}
//将结构体(struct info)数组的元素,按照身高进行排序
void sort_by_height(struct