用指针应用编写一个存储学生信息的顺序表,只需要编写创建,初始化和打印部分
时间: 2023-05-24 18:04:26 浏览: 66
#include <stdio.h>
typedef struct student {
char name[20]; // 姓名
int age; // 年龄
int score; // 分数
} Student;
#define MAX_SIZE 100 // 学生信息数组的最大大小
void create(Student *students, int size); // 创建学生信息数组
void init(Student *students, int size); // 初始化学生信息数组
void print(Student *students, int size); // 打印学生信息数组
int main() {
Student students[MAX_SIZE]; // 学生信息数组
int size; // 学生信息数组大小
printf("请输入学生信息的数量:");
scanf("%d", &size);
create(students, size);
init(students, size);
print(students, size);
return 0;
}
void create(Student *students, int size) {
for (int i = 0; i < size; i++) {
printf("请输入第%d个学生的姓名、年龄、分数:", i + 1);
scanf("%s%d%d", (students + i)->name, &(students + i)->age, &(students + i)->score);
}
}
void init(Student *students, int size) {
for (int i = 0; i < size; i++) {
printf("初始化第%d个学生的信息:", i + 1);
(students + i)->age = 0;
(students + i)->score = 0;
}
}
void print(Student *students, int size) {
printf("学生信息如下:\n");
for (int i = 0; i < size; i++) {
printf("%s\t%d\t%d\n", (students + i)->name, (students + i)->age, (students + i)->score);
}
}
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)