博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
多文件调用(函数、结构体)
阅读量:4325 次
发布时间:2019-06-06

本文共 1240 字,大约阅读时间需要 4 分钟。

main.m文件

int main(int argc, const char * argv[])

{

    struct student stu1;

    struct student stu2 = {"李四",16,98};//extern

    struct student stu3 = {"王五",21,99};

    strcpy(stu1.name,"张三");

    stu1.age = 17;

    stu1.grade = 96.5;

    struct student *p = &stu1;

    strcpy((*p).name, "潘俊飞");

    strcpy(p->name, "郭刚");

    struct student array[3] = {stu1,stu2,stu3};

    int length = sizeof(array)/sizeof(struct student);

    printf("结构体数组的长度:%d\n",length);

    struct student *pstruct = array;

    pstruct = &array[0];

    (pstruct+1)->age = 30;

    //printf("%d\n",array[1].age);

    sortAge(pstruct,length);

    print(pstruct,length);

    return 0;

}

 

 

Funcation.h文件

struct student{

    char name[30];

    int age;

    float grade;

}stu1;

void sortAge(struct student *a,int count);

void print(struct student *a,int count);

 

Funcation.m文件

 

#import "Funcation.h"

 

//@implementation Funcation

//

//@end

 

void sortAge(struct student *p,int count){

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

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

            if (((p+j)->age)>((p+j+1)->age)) {

                struct student temp = *(p+j+1);

                *(p+j+1) = *(p+j);

                *(p+j) = temp;

            }

        }

    }

    

}

void print(struct student *a,int count){

    printf("学生信息列表:\n");

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

        printf("%s\t%d\t%.2f\n",(a+i)->name,(a+i)->age,(a+i)->grade);

    }

}

转载于:https://www.cnblogs.com/jyq-blog/p/4435008.html

你可能感兴趣的文章
使用php后台给自己做一个页面路由,配合ajax实现局部刷新。
查看>>
类与对象(二)
查看>>
NSString 的常用方法
查看>>
mysql的engine不同,导致事物回滚失败的问题
查看>>
JAVAWeb使用POI做导出Excel
查看>>
今天解决了首页无头像被显示的问题
查看>>
charts 画折线图
查看>>
[py]__name__ 属于哪个文件
查看>>
技术分析淘宝的超卖宝贝
查看>>
i++和++1
查看>>
react.js
查看>>
实验四【bx】和loop的使用
查看>>
P1313 计算系数
查看>>
myBatis之入门示例
查看>>
tensorflow 变量共享
查看>>
NSString的长度比较方法(一)
查看>>
初识JavaScript
查看>>
Azure云服务托管恶意软件
查看>>
My安卓知识6--关于把项目从androidstudio工程转成eclipse工程并导成jar包
查看>>
旧的起点(开园说明)
查看>>