作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我第一次在结构中使用结构。我在编译我的程序时遇到了这个错误。错误:字段“结果”的类型不完整。
错误是指这行代码。-->结构result_t结果;
有什么帮助吗? :)谢谢。
typedef struct {
char moduleCode[8];
char grade[3];
} result_t;
typedef struct {
char name[31];
struct result_t results;
} student_t;
编辑:
我更改了我的代码:
typedef struct {
char moduleCode[8];
char grade[3];
} result_t;
typedef struct {
char name[31];
result_t results;
} student_t;
我得到了一个新的编译错误。错误:下标值既不是数组也不是指针。
触发该错误的代码行如下。printf("%-7s %-2s %d\n", student.results[i].module_code, student.results[i].grade, student.results[i].mc);
最佳答案
结果不是数组。你应该改变结构学生:
typedef struct {
char name[31];
result_t results[MAX_NUM_RESULTS];
} student_t;
或者将 printf 更改为:
printf(" %-7s %-2s %d\n", student.results.module_code, student.results.grade, student.results.mc);
这取决于一个学生可能有多少种结果。
关于c - HiC : Structure within Structure?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13247853/
这是我第一次在结构中使用结构。我在编译我的程序时遇到了这个错误。错误:字段“结果”的类型不完整。 错误是指这行代码。-->结构result_t结果; 有什么帮助吗? :)谢谢。 typedef str
我是一名优秀的程序员,十分优秀!