zoukankan      html  css  js  c++  java
  • 通过函数完成对结构体变量的输入输出

    /*
    //2020年11月19日17:24:42
    #include<stdio.h>
    #include<string.h>
    void InputStudent(struct Student);
    struct Student
    {
        int age;
        char sex;
        char name[100];
    };
    int main(void)
    {
        struct Student st;
        InputStudent(st);
        printf("%d %c %s",st.age,st.sex,st.name);
        return 0;
    }
    void InputStudent(struct Student stu)
    {
        stu.age=10;
        strcpy(stu.name,"zhangsan");
        stu.sex='F';
    }*/
    /*
    #include<stdio.h>
    #include<string.h>
    void InputStudent(struct Student *);
    struct Student
    {
        int age;
        char sex;
        char name[100];
    };
    int main(void)
    {
        struct Student st;
        InputStudent(&st);
        printf("%d %c %s",st.age,st.sex,st.name);
        return 0;
    }
    void InputStudent(struct Student * pstu)
    {
        pstu->age=10;
        strcpy(pstu->name,"zhangsan");
        pstu->sex='F';
    }*/
    /*
    #include<stdio.h>
    #include<string.h>
    //通过函数完成结构体变量的输入和输出
    //2020年11月19日17:34:42
    void InputStudent(struct Student *);
    void OutputStudent(struct Student );
    struct Student
    {
        int age;
        char sex;
        char name[100];
    };
    int main(void)
    {
        struct Student st;
        InputStudent(&st);//对结构体变量输入,要设计修改,必须发送st的地址
        //printf("%d %c %s",st.age,st.sex,st.name);
        OutputStudent(st);//对结构体变量输出,可以发送st的地址也可以发送st,因为不涉及修改
        return 0;
    }
    void InputStudent(struct Student * pstu)
    {
        pstu->age=10;
        strcpy(pstu->name,"zhangsan");
        pstu->sex='F';
    }
    void OutputStudent(struct Student ss)
    {
       printf("%d %c %s",ss.age,ss.sex,ss.name); 
    }*/
    #include<stdio.h>
    #include<string.h>
    //通过函数完成结构体变量的输入和输出
    //2020年11月19日17:41:45
    void InputStudent(struct Student *);
    void OutputStudent(struct Student *);
    struct Student
    {
        int age;
        char sex;
        char name[100];
    };
    int main(void)
    {
        struct Student st;
        InputStudent(&st);//对结构体变量输入,要设计修改,必须发送st的地址
        //printf("%d %c %s",st.age,st.sex,st.name);
        printf("%d
    ",sizeof(st));
        OutputStudent(&st);//对结构体变量输出,可以发送st的地址也可以发送st,因为不涉及修改
        //但为了减少内存占用,也为了提高执行速度,推荐发送地址
        return 0;
    }
    void InputStudent(struct Student * pstu)
    {
        pstu->age=10;
        strcpy(pstu->name,"zhangsan");
        pstu->sex='F';
    }
    void OutputStudent(struct Student * ss)
    {
       printf("%d %c %s",ss->age,ss->sex,ss->name); 
    }
  • 相关阅读:
    调度思想-现实中的事物与技术里面其实存在类似道理(转载收藏的一篇好文)
    使用curl发送post或者get数据
    论技术的重要性(转载的一篇文章)
    facebook工具xhprof的安装与使用-分析php执行性能(转载)
    (转载)网站瓶颈发现和解决
    mysql不乱码的思想总结
    如何在同一台机器上安装多个MySQL的实例
    awk的常用操作场景以及工作中涉及到的一些场景实例
    Linux中的yum的配置以及常见报错的处理
    (转载)感触比较深的一篇文章
  • 原文地址:https://www.cnblogs.com/ajiaoa/p/14007980.html
Copyright © 2011-2022 走看看