C/C++ 结构体 数组 函数传递

时间:2023-12-17 20:11:20
 #include <stdio.h>
#include <stdlib.h> struct student{
int num;
char str[];
double dec;
}; void scan(struct student stu[], int *n){
scanf("%d", n);
for(int i = ; i < *n; ++i){
scanf("%d%s%lf", &stu[i].num, stu[i].str, &stu[i].dec);
}
} void print(struct student stu[], int n){
printf("%d\n", n);
for(int i = ; i < n; ++i){
printf("%d %s %lf\n", stu[i].num, stu[i].str, stu[i].dec);
}
} int main(){
int n;
struct student stu[]; scan(stu, &n);
print(stu, n); return ;
}
/*
3
20 字符串0 20.02
21 字符串1 21.12
22 字符串2 22.22
*/