zoukankan      html  css  js  c++  java
  • 多文件调用(函数、结构体)

    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 ",length);

        struct student *pstruct = array;

        pstruct = &array[0];

        (pstruct+1)->age = 30;

        //printf("%d ",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("学生信息列表: ");

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

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

        }

    }

  • 相关阅读:
    关于ASM磁盘
    Oracle关于用户信息的一些SQL语句
    Java环境下Tomcat的配置与部署Geoserver及其简单使用
    ArcGis 栅格计算器中表达式一栏不显示的解决方法
    springboot整合redis缓存一些知识点
    XXX银行人事管理系统-数据库设计
    JQuery攻略读书笔记---第2章 数组
    离别
    mysql 的引擎
    存储示例
  • 原文地址:https://www.cnblogs.com/jyq-blog/p/4435008.html
Copyright © 2011-2022 走看看