怎么能让我的input(),seek(),calculate(),output(),sort()函数全用指针来实现,而且是用指针访问一维数组
#include <stdio.h>#include <conio.h>
#include <string.h>
struct student {
long num;
char name[20];
char sex[2];
int age;
struct Grade {
int Math;
int Computer;
int Physics;
int English;
} gra;
int total;
float average;
};
void calculate(struct student stu[], int n);
void input(struct student stu[], int n);
void output(struct student stu[], int n);
void seek(struct student stu[], int n);
void sort(struct student stu[], int n);
int main() {
struct student stu[5];
input(stu, 5);
calculate(stu, 5);
output(stu, 5);
sort(stu, 5);
printf("排序后:\n");
output(stu, 5);
seek(stu, 5);
} void seek(struct student stu[], int n) {
char name[20];
int i;
printf("\n请输入查找的同学的姓名:\n");
scanf("%s", name);
for (i = 0; i < n; i++) {
if (strcmp(name, stu[i].name) == 0) {
printf("学号:%d\n", stu[i].num);
printf("姓名:%s\n", stu[i].name);
printf("性别:%s\n", stu[i].sex);
printf("年龄:%d\n", stu[i].age);
printf("高数成绩:%d\n", stu[i].gra.Math);
printf("计算机成绩:%d\n", stu[i].);
printf("物理成绩:%d\n", stu[i].gra.Physics);
printf("英语成绩:%d\n", stu[i].gra.English);
printf("总成绩:%d\n", stu[i].total);
printf("平均成绩:%f\n", stu[i].average);
break;
}
}
if (i == n) {
printf("No find\n");
}
}
void sort(struct student stu[], int n) {
struct student s = { 0 };
int i, j;
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - 1; j++) {
if (stu[j].total < stu[j + 1].total) {
memcpy(&s, &stu[j], sizeof(struct student));
memcpy(&stu[j], &stu[j + 1], sizeof(struct student));
memcpy(&stu[j + 1], &s, sizeof(struct student));
}
}}} void input(struct student stu[], int n) {
int i;
for (i = 0; i < n; i++) {
printf("\n请输入第%d个同学的学号:\n", i + 1);
scanf("%d", &stu[i].num);
printf("\n请输入第%d个同学的姓名:\n", i + 1);
scanf("%s", stu[i].name);
printf("\n请输入第%d个同学的性别:\n", i + 1);
scanf("%s", stu[i].sex);
printf("\n请输入第%d个同学的年龄:\n", i + 1);
scanf("%d", &stu[i].age);
printf("\n请输入第%d个同学的高数成绩:\n", i + 1);
scanf("%d", &stu[i].gra.Math);
printf("\n请输入第%d个同学的计算机成绩:\n", i + 1);
scanf("%d", &stu[i].);
printf("\n请输入第%d个同学的物理成绩:\n", i + 1);
scanf("%d", &stu[i].gra.Physics);
printf("\n请输入第%d个同学的英语成绩:\n", i + 1);
scanf("%d", &stu[i].gra.English);
}
}
void calculate(struct student stu[], int n) {
int i;
for (i = 0; i < n; i++) {
stu[i].total =
stu[i].gra.Math + stu[i]. + stu[i].gra.Physics +
stu[i].gra.English;
stu[i].average = (float)stu[i].total / 4;
printf("输出第%d个同学的总成绩:%d\n", i + 1, stu[i].total);
printf("输出第%d个同学的平均成绩:%f\n", i + 1, stu[i].average);
}} void output(struct student stu[], int n) {
int i;
for (i = 0; i < n; i++) {
printf("学号:%d\n", stu[i].num);
printf("姓名:%s\n", stu[i].name);
printf("性别:%s\n", stu[i].sex);
printf("年龄:%d\n", stu[i].age);
printf("高数成绩:%d\n", stu[i].gra.Math);
printf("计算机成绩:%d\n", stu[i].);
printf("物理成绩:%d\n", stu[i].gra.Physics);
printf("英语成绩:%d\n", stu[i].gra.English);
printf("总成绩:%d\n", stu[i].total);
printf("平均成绩:%f\n", stu[i].average);
}
}