I'm having some issues using writing code using the type def statments in unison with the member access operator. I want to allot the value, see below, the my structure defined variables. But each time I give it a try I go further down the spiral and confuse myself. What am I doing wrong? Why won't this program print the different values?
#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
is a structure, not an int
, so using %d
for the format code won't work.
Use something like
printf("start %d %d %d\\n", course.start.day, course.start.month, course.start.year);
除printf问题外,还应将路线变量传递给main中的outputDate()函数。
outputDate(course);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.