c - 使用 typedef 结构分配值

标签 c structure typedef

我在使用 type def 语句与成员访问运算符一起编写代码时遇到了一些问题。我想分配我的结构定义变量的值,见下文。但每次我尝试时,我都会进一步陷入困境并使自己感到困惑。我究竟做错了什么?为什么这个程序不打印不同的值?

#include <stdio.h>

void outputDate(courseInfo course);

typedef struct{
    int year;
    int month;
    int day;
}date;

typedef struct{
    double avrage;
    int students;
    date start;
    date end;

}courseInfo;

int main(void){

    courseInfo course;
    course.avrage = 10;
    course.students=200
    course.start={17,17,17};
    course.end={16,16,16};


    outputDate();

    return 0;
}

void outputDate(courseInfo course){
    printf("avrage%d\n", course.avrage);
    printf("students%d\n", course.students);
    printf("start%d\n", course.start);
    printf("end%d\n", course.end);
    return;
}

最佳答案

start 是一个结构体,而不是 int,因此使用 %d 作为格式代码不起作用。
使用类似的东西
printf("start %d %d %d\n", course.start.day, course.start.month, course.start.year);

关于c - 使用 typedef 结构分配值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46780683/

相关文章:

C 文件处理 - 整数值 13 不能写入文件

Tomcat:源服务器未找到目标资源的当前表示或不愿意透露存在该表示

java - 与eclipse不同的网站目录结构

svn - 建立SVN开发结构

c - 在 C 中使用带指针的结构和数组

编译器给出一个名为 Unknown type name 的错误

c - 使用 pic16f877a 进行太阳跟踪器步进电机仿真

c - BeagleBone 黑色 : UART crashes the BBB after two successful read write calls

纸板.c :12:1: warning: control reaches end of non-void function [-Wreturn-type]

c++ - typedef 函数指针?