结构体数组
结构体数组的定义:具有相同结构体类型的结构体变量组成的数组
定义结构体数组的方法和定义结构体变量的方法类似。
eg:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#include<stdio.h> #include<string.h> #define N 10 struct student { int SID; char name[N]; float score; } s2[2]; int main() { int i; struct student s1[2]={{1,"s1",99},{2,"s2",88}}; printf(" %d %s %.2fn",s1[0].SID,s1[0].name,s1[0].score); int len=sizeof(s2)/sizeof(struct student);//求结构体数组长度 for(i=0;i<len;i++) { printf("input sidn"); scanf("%d",&s2[i].SID); printf("input namen"); scanf("%s",s2[i].name); printf("input scoren"); scanf("%f",&s2[i].score); } for(i=0;i<len;i++) { printf(" %d %s %.2fn",s2[i].SID,s2[i].name,s2[i].score); } return 0; }
结果:
最后
以上就是无奈发带最近收集整理的关于结构体数组定义的全部内容,更多相关结构体数组定义内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复