一、问题描述
自己用c语言结构体和数组写了一个对学生简单的分类小程序,包括姓氏相同,年龄相同,身高相仿,体重相仿,运动爱好相同,喜欢的食堂相仿。自己写的比较复杂,有什么可以改善的欢迎讨论。
二、代码
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define Num 20
typedef struct{
//生成一个学生信息结构体
char name[2][Num]; //姓,名
int old; //年龄
double height; //身高
double weight; //体重
char sport_hobby[30]; //运动爱好
char canteen[30]; //喜欢哪个食堂
}student;
void firstname_sort(student stu[]);
void Old_sort(student stu[]);
void height_sort(student stu[]);
void weight_sort(student stu[]);
void sporthooby_sort(student stu[]);
void canteen_sort(student stu[]);
int main()
{
student stu[Num]={
{
"chen","zhou",21,170,130,"basketball","zhongxing"},
{
"jiang","yuguo",22,172.23,155.4,"badminton","qianxihe"},
{
"wang","hong",23,180.5,149.3,"soccer","honggaoliang"},
{
"chen","yuqi",23,167,110,"pingpong","zhongxing"},
{
"xu","jing",22,158,100,"pingpong","xingyeyuan"},
{
"liu","qiang",21,177.5,120.5,"basketball","qianxihe"},
{
"yang","qinghua",19,173.5,119.6,"soccer","honggaoliang"},
{
"jiang","feng",20,172,108,"badminton","xingyeyuan"},
{
"xu","hao",19,174,119,"vollyball","qianxihe"},
{
"wang","qi",20,169,110,"pingpong","zhongxing"},
{
"chen","zhi",21,177,112,"vollyball","honggaoliang"},
{
"liu","li",23,185,128,"basketball","daxibei"},
{
"xu","chaoyang",21,177,130,"soccer","honggaoliang"},
{
"jiang","ke",20,183,144,"basketball","zhongxing"},
{
"wang","fan",22,172,140,"badminton","yansheng"},
{
"liu","handing",21,172,138,"soccer","yansheng"},
{
"yang","xiao",20,177,128,"pingpong","daxibei"},
{
"xu","zhong",23,182,140,"badminton","yansheng"},
{
"wang","keyi",19,168,100,"pingpong","qianxihe"},
{
"liu","dexuan",23,175,130,"basketball","zhongxing"}
};
int i