写一函数查找成绩90分以上的学员,使⽤回调函数在姓名后加”⾼富帅”

             

             main文件下

    struct student stu1 = {"zhangsan",95.0};

    struct student stu2 = {"lisi",80.0};

    struct student stu3 = {"wangwu",91.0};

    struct student stu4 = {"zhaoliu",75.0};

    struct student stu5 = {"chenqi",89.0};

    

    struct student array[5]={stu1,stu2,stu3,stu4,stu5};

    findHighScore(array, 5, strcatName);

    for (int i = 0; i < 5; i++) {

        printf("%s\n",array[i].name);


                             //.h文件下


struct student{

    char name[100];

    float score;

};

//声明一个给名字前面加高富帅的函数

void strcatName(char *p);

//声明一个查找90分以上学员的函数

void findHighScore(struct student *p,int count,void(*addName)(char *));


                          .m文件下


void strcatName(char *p)

{

    strcat(p, "高富帅");

}

void findHighScore(struct student *p,int count,void(*addName)(char *))

{

    for (int i = 0; i < count; i++) {

        if (p[i].score >= 90) {//寻找结构体里面分数大于90分的学员

            addName(p[i].name);//函数回调,把找到的90分以上的学员,名字后面拼接高富帅

        }

    }

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值