求助c语言

大佬们,怎么把这个代码的指针改为数组?

就是这个void inputStudent(Student * student);
void inputStudents(Student students[], int * count);
急急急

#include <stdio.h>
#include<string.h> 
#define STUDENTCOUNT 50
#define SUBJECTCOUNT 5

struct str_Student {
	char number[20];
	char name[20];
	char gender[20];
	float scores[SUBJECTCOUNT];
};
typedef struct str_Student Student;

void inputStudent(Student * student);
void outputStudent(Student student);
int findStudentByNumber(Student students[], char number[], int count);
void inputStudents(Student students[], int * count);

int main() 
{
	Student students[STUDENTCOUNT];
	int i = 0; 
	int j = 0;
	int index = 0;
	int choice = 0;
	int count = 0;
	Student temp;
	char number[20];

	FILE * fp = NULL;

	printf("欢迎使用学生信息管理系统!\n");		// 
	do 
	{
		printf("1.输入 2.输出 3.插入 4.删除 5.修改 6.查找 7.排序 8.保存 9.加载 0.退出\n");
		printf("请选择:");
		scanf("%d", &choice);
		switch (choice) 
		{
		case 1:
			inputStudents(students, &count);
			break;
		case 2:	// outputStudents(students, count);
			// ...
			printf("\t\t\t\t成绩单\n");
			printf("学号\t姓名\t性别\t语文\t数学\t英语\t物理\t化学\n");
			for (i = 0; i < count; i++) {
				outputStudent(students[i]);
			}
			break;
		case 3:	// insertStudent(students, &count);
			printf("请输入要插入的位置:");
			scanf(" %d", &index);

			for (i = count; i >= index; i--) {
				students[i] = students[i - 1];
			}

			inputStudent(&students[i]);
			count++;
			break;
		case 4:	// deleteStudent(students, &count);
			printf("请输入要删除的学号:");
			scanf(" %s", number);

			index = findStudentByNumber(students,number, count) + 1;

			if (index < 0)
				printf ("未找到该学号。\n");
			else 
			{
				for (i = index; i < count; i++) {
					students[i - 1] = students[i];
				}
				count--;
			}
			break;
		case 5:	// modifyStudent(students, count);
			printf("请输入要修改的学号:");
			scanf(" %s", number);

			index = findStudentByNumber(students,number, count);

			if (index < 0)
				printf ("未找到该学号。\n");
			else 
			{
				outputStudent(students[index]);
				inputStudent(&students[index]);
			}
			break;
		case 6:	// findStudent(students, count);
			printf("请输入要查找的学号:");
			scanf(" %s", number);
			
			index = findStudentByNumber(students,number, count);

			if (index < 0)
				printf ("未找到该学号。\n");
			else 
			{
				printf("学号为%s的学生信息是:\n", number);
				outputStudent(students[index]);
			}
			break;
		case 7:	// sortStudents(students, count);
			for (i = 0; i < count - 1; i++)
			{
				for (j = 0; j < count - 1 - i; j++)
				{
					if (strcmp(students[i].number, students[i + 1].number) < 0)
					{
						temp = students[i];
						students[i] = students[i+ 1];
						students[i + 1] = temp;
					}
				}
			}
			break;
		case 8:	// saveStudents(students, count);
			fp = fopen("C:\\Students.txt", "w");
			if (fp != NULL) {
				for (i = 0; i < count; i++) {
					fprintf(fp, "%s\t", students[i].number);
					fprintf(fp, "%s\t", students[i].name);
					fprintf(fp, "%s\t", students[i].gender);
					for (j = 0; j < SUBJECTCOUNT; j++) {
						fprintf(fp, "%.2f\t", students[i].scores[j]);
					}
					fprintf(fp, "\n");
				}
				fclose(fp);
			}
			else
				printf("写文件失败,不能保存!\a\n");
			break;
		case 9:	// loadStudents(students, &count);
			fp = fopen("C:\\Students.txt", "r");
			if (fp != NULL) {
				for (i = 0; ; i++) {
					fscanf(fp, "%s", students[i].number);
					fscanf(fp, "%s", students[i].name);
					fscanf(fp, "%s", students[i].gender);
					for (j = 0; j < SUBJECTCOUNT; j++) {
						fscanf(fp, "%f", &students[i].scores[j]);
					}
					// 判断是否已是文件尾 end of file
					if (feof(fp))
						break;
				}
				count = i;
				fclose(fp);
			}
			else
				printf("读文件失败,不能加载!\a\n");
			break;
		case 0:
			printf("谢谢使用学生信息管理系统!\n");
			break;
		default:
			printf("暂无该功能!\n");
			break;
		}
	} while (choice != 0);
	
	return 0;
}

void inputStudent(Student * pStudent)
{
	int j;
	printf("请输入学号:");
	scanf(" %s", pStudent->number);	// %s前的空格避免了缓存中换行符的影响
	printf("请输入姓名:");
	scanf(" %s", pStudent->name);	// %s前的空格避免了缓存中换行符的影响
	printf("请输入性别:");
	scanf(" %s", pStudent->gender);	// %s前的空格避免了缓存中换行符的影响
	for (j = 0; j < SUBJECTCOUNT; j++) {
		printf("请输入%s的第%d科成绩:", pStudent->name, j + 1);
		scanf("%f", &pStudent->scores[j]);
	}
}
void outputStudent(Student student)
{
	int j;
	float sum = 0;
	printf("%s\t", student.number);
	printf("%s\t", student.name);
	printf("%s\t", student.gender);
	for (j = 0; j < SUBJECTCOUNT; j++) {
		printf("%.2f\t", student.scores[j]);
		sum += student.scores[j];
	}
	printf("%.2f\n", sum);
}

int findStudentByNumber(Student students[], char number[], int count)
{
	int i;
	for (i = 0; i < count; i++) {
		if (strcmp(students[i].number, number) == 0)
			return i;
	}
	return -1;
}
void inputStudents(Student students[], int * count)
{
	int i;
	char choice;
	for (i = 0; i < STUDENTCOUNT; i++) {
		inputStudent(&students[i]);

		(*count)++;
		printf("是否继续(Y|N)?");
		scanf(" %c", &choice);
		if (choice != 'Y' && choice != 'y')
			break;
	}

}
相关推荐
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页