学生成绩管理系统(C语言)(数组结构体)

一、设计目标:

学生成绩管理系统

利用结构体、排序查找算法以及模块化程序设计实现如下菜单驱动的学生成绩管理系统:

1) 首次批量输入每个学生的学号、姓名、和各科考试成绩。

2) 增添一个新学生的信息。

3) 增添一门新的学科的信息。

4) 按学生姓名或学号查询、修改、删除学生信息。

5) 计算每门课程的总分和平均分。

6) 计算每个学生的总分、平均分以及排名。

7) 按总分从高到低(从低到高)排名并输出。

8) 按学号大小排名并输出。

9) 按学生姓名首字母排名并输出。

10) 按优秀(90-100分)、良好(80-90分)、中等(70-80分)、及格(60-70分)、不及格(0-60分)5个类别,对每门课程分别统计每个类别的人数以及所占百分比。

11) 输出每个学生的学号、姓名、各科考试成绩。

12) 将每个学生的成绩写入文件。

13) 从文件读取学生成绩并显示。

二、设计思路

本程序主要采用了、for循环完成录入、排序以及成绩筛选、函数、switch实现功能选择等方法。

                                                                   程序流程图

三.代码部分

/*
Student scores mangement system V1.0
C Programming Final-examination
Written by Charles 
2022.5.27 - 6.7
*/

#include<stdio.h>
#include<windows.h> 
#include<stdlib.h>
#include<string.h> 


int n = 0, course = 0;         //The number of students; The number of courses


struct student         
{
	char id[18];        //student id
	char name[10];      //student name 
	float score[6];    //student score
	float sum;         //student sum score
	float ave_stu;     //student course average course
} stu[30], temp;


void welcome();           //The start page
void inputinfo();         //Input student`s information 
void addinfo();           //Add student`s information
void deleteinfo();        //Delete student`s information
void changeinfo();        //Change student`s information
void searchinfo();        //Search student`s information
void infocount();         //Information count
void quitapp();           //Quit the application
void output(char name[]); //Output the information
void outtxt();            //Output text 

void showinfo(char str[4]);          //Show student`s information on display
int findstu(char a[2]);              //Find student`s information
void ave();                          //Course average score      
void sum();                          //Course sum score          
void max_();                         //Each courses` highest score  
void htl();                          //High score to low score      
void lth();                          //Low score to high score 
void full();                         //Full student information
void eachcour();                     //Each student`s new score     
void namesort();                     //Studet`s name sort
void idsort();                       //student`s id sort
void presents();                     //Each courses` each scores` present 

void readfile();                     //Readfile
void save();                        //Save the information

 
int main()                                           // main
{
    int choice = 0, re;
    begin: welcome();
    scanf("%d", & choice);
    switch(choice)
    {
    	case 0 : inputinfo();    //Input student information
    		break;
    	case 1 : addinfo();      //Add student information    
    	    break;
    	case 2 : deleteinfo();   //Delete student information
    		break;
    	case 3 : changeinfo();   //Change student information
    		break;
    	case 4 : searchinfo();   //Search student information 
    		break;
    	case 5 : infocount();    //Information count
    		break;
    	case 6 : outtxt();                  //Output txt
    		break;	
    	case 7 : readfile();
		         showinfo("全班信息");      //Show classmates information
    		break;			
    	case 8 : quitapp();                 //Quit the application
    		break;	
	}
	printf("-------------------------------------\n");
    printf("        操作成功,是否继续操作       \n");
    printf("-------------------------------------\n");	
    printf("        是:1            否:0       \n"); 
    scanf("%d", &re); 
    switch(re)
    {
    	case 1: goto begin;
    		break;
    	case 0: quitapp();
    	    break;
	}
    return 0;
}


void welcome()                                       // The start page
{
	system("cls");
    printf("-------------------------------------\n");
    printf("          学生成绩管理系统           \n");
    printf("-------------------------------------\n");
    printf("请输入数字序列号,选择您要执行的操作\n");
    printf("0.录入学生信息\n");
    printf("1.添加学生信息\n");
    printf("2.删除学生信息\n");
    printf("3.修改学生信息\n");
    printf("4.查询学生信息\n");
    printf("5.成绩分析\n");
    printf("6.输出全班同学信息\n");
    printf("7.显示全班同学信息\n");
    printf("8.退出学生管理系统\n");
    printf("-------------------------------------\n");
}


void inputinfo()                                       // Input students` information 
{
	int i, j, re;
	system("cls");
	printf("-------------------------------------\n");
    printf("           0.学生信息录入            \n");
    printf("-------------------------------------\n");
	printf("输入学生个数:\n"); 
	scanf("%d", &n);
	printf("输入考试科目个数:\n");
	scanf("%d", &course);
	printf("输入学生信息:\n");
	printf("(eg:XXXXXXX(学号) XXXXXXXXX(姓名) XXX XXX XXX XXX(各科成绩) )\n");  
	for(i = 0; i < n; i++)
	{
	    for(j = 0; j < 18; j++)
	    {
	    	scanf("%c", &stu[i].id[j]);
	    	if(stu[i].id[j] == ' ')
			{
				stu[i].id[j] = '\0';
				break;	
			} 
		}                                     
		for(j = 0; j < 10; j++)
	    {
	    	scanf("%c", &stu[i].name[j]);
	    	if(stu[i].name[j] == ' ')
			{
				stu[i].name[j] = '\0';
				break;	
			} 
		}
		stu[i].sum = 0;
		for(j = 0; j < course; j++)
		{
			scanf("%f", &stu[i].score[j]);
			stu[i].sum = stu[i].sum	+ stu[i].score[j];
		}
		stu[i].ave_stu = stu[i].sum / course;	
	} 
	save();
}  


void addinfo()                                       // Add students` information  
{
	int j, choice;
	readfile();
    system("cls");
	printf("-------------------------------------\n");
    printf("           1.学生信息增添            \n");
    printf("-------------------------------------\n"); 
    printf("    请输入需要添加学生信息的类型:\n");
    printf("一个新的学生(1) 一门新的科目(2)\n");
    printf("-------------------------------------\n"); 
    scanf("%d", &choice);
    switch(choice)
    {
    	case 1 : full();
    		break;
    	case 2 : eachcour();
    		break;
    }
    save();
    printf("-------------------------------------\n"); 
	printf("   是否输出数据:是(1)     否(0)\n");
	printf("-------------------------------------\n"); 
	scanf("%d", &choice); 
	switch(choice)
	{
		case 1 : output("学生成绩表.txt"); 
			break; 
		case 0 : break;
	}
}
 
 
void deleteinfo()                                   // Delete information from the file      
{
	int s, i, j, choise;
	char name[30] = {'\0'};
    readfile();
    system("cls");
    printf("-------------------------------------\n");
    printf("           2.学生信息删除            \n");
    printf("-------------------------------------\n");
    s = findstu("删除");
    strcpy(name, stu[s].name);
    printf("-------------------------------------\n");
    printf(" 是否将%s的信息删除:是(1)  否(0) \n", name);
	printf("-------------------------------------\n");
	scanf("%d", &choise); 
	switch(choise)
	{
		case 1 : for(i = s;i < n - 1; i++)
				{
					stu[i] = stu[i + 1];
				}
				n--;
				save(); 
				printf("-------------------------------------\n"); 
				printf("        已将%s的信息删除\n", name);
				printf("-------------------------------------\n");  
				printf("   是否输出数据:是(1)     否(0)\n");
				printf("-------------------------------------\n"); 
				scanf("%d", &choise); 
				switch(choise)
				{
					case 1 : output("学生成绩表.txt"); 
						break; 
					case 0 : break;
				}
		case 0 : break;
	}
}   


void changeinfo()                                   // Change the information from the file     
{
	int i, j, s, choice;
	char change[30] = {'\0'};
	float ch = 0.00;
	readfile();
	system("cls");
	printf("-------------------------------------\n");
    printf("           3.学生信息修改            \n");
    printf("-------------------------------------\n");
    s = findstu("修改");
	printf("-------------------------------------\n"); 
    printf("请选择需要修改%s的信息选项:\n", stu[s].name);
    printf("学号(1), 姓名(2),成绩(3)\n");
    printf("-------------------------------------\n"); 
    scanf("%d", &choice);
    switch(choice)
    {
    	case 1:printf("请输入新的学号:\n");
    	    scanf("%s", &stu[s].id);
    	    printf("-------------------------------------\n"); 
    	    printf("         已成功修改%s同学学号\n", stu[s].name); 
    	    printf("-------------------------------------\n"); 
    		break;
    	case 2:printf("请输入修改后的姓名:\n");
    		scanf("%s", &stu[s].name);
    	    printf("-------------------------------------\n"); 
    	    printf("         已成功修改%s同学姓名\n", stu[s].name); 
    	    printf("-------------------------------------\n"); 
    		break;
    	case 3:printf("请输入想要修改的科目位号:(eg:科目一:1)\n");
    	       scanf("%d", &choice);
			   printf("请输入修改后科目%d的分数:\n", choice);
			   stu[s].sum = stu[s].sum - stu[s].score[choice - 1];
			   scanf("%f", &stu[s].score[choice - 1]);
			   stu[s].sum = stu[s].sum + stu[s].score[choice - 1];
			   stu[s].ave_stu = stu[s].sum / course;
    }
    save();
    printf("-------------------------------------\n"); 
	printf("   是否输出数据:是(1)     否(0)\n");
	printf("-------------------------------------\n"); 
	scanf("%d", &choice); 
	switch(choice)
	{
		case 1 : output("学生成绩表.txt"); 
			break; 
		case 0 : break;
	}
}   


void searchinfo()                                    // Search information            
{
	int i, j; 
	readfile();
	system("cls");
	printf("-------------------------------------\n");
    printf("           4.学生信息查询            \n");
    printf("-------------------------------------\n");
    i = findstu("查询");
    printf("-------------------------------------\n");
    printf("总排名    学号        姓名");
	for(j = 1; j < course; j++)
	{
		printf("%5d  ", j);
	} 
	printf("%5d", course);
    printf("   总分  平均分\n");
	printf("-------------------------------------\n"); 
    printf("\n%3d、", i + 1);
	printf(" %10s ", stu[i].id);
    printf("%10s ", stu[i].name);
    for(j = 0; j < course; j++)
    {
    	printf("%5.2f ", stu[i].score[j]);
    } 
    printf("%5.2f %5.2f\n", stu[i].sum, stu[i].ave_stu);   
}


void infocount()                                    // Information count             
{
	system("cls");
	readfile();
	printf("-------------------------------------\n");
    printf("           5.学生成绩分析            \n");
    printf("-------------------------------------\n");
	int i, j, n, m, choice; 
	printf("选择您需要的信息:(请输入数字)\n");
	printf("1. 各个学科的成绩总和\n"); 
	printf("2. 各个学科的平均分\n"); 
	printf("3. 各个学科的最高分\n");
	printf("4. 将成绩从低到高排序\n");
	printf("5. 将成绩从高到低排序\n");
	printf("6. 各科各个分数段组成占比\n");
	printf("-------------------------------------\n"); 
	scanf("%d", &choice);
	switch(choice)
	{
		case 1 : sum();
			break;
		case 2 : ave(); 
			break; 
		case 3 : max_(); 
			break; 
		case 4 : lth();
			break;
		case 5 : htl();
			break;
		case 6 : presents();
			break;
	}
	if(choice == 4 || choice == 5)
	{
		printf("-------------------------------------\n"); 
		printf("   是否显示信息:是(1)    否(0)\n");
		printf("-------------------------------------\n"); 
		scanf("%d", &n);
		switch(n)
		{
			case 1 : switch(choice)
					{
						case 4 : showinfo("从低到高");
							break; 
						case 5 : showinfo("从高到低");
							break;
					}			
			case 0 : break;
		}
		printf("-------------------------------------\n"); 
		printf("   是否输出数据:是(1)     否(0)\n");
		printf("-------------------------------------\n"); 
		scanf("%d", &n); 
		switch(n)
		{
			case 1 : switch(choice)
					{
						case 4 : output("从低到高排序的成绩单.txt");
							break; 
						case 5 : output("从高到低排序的成绩单.txt");
							break;
					}   			
			case 0 : break;
		}
	}
	
}   


void outtxt()                                    // Output information            
{
	int choice; 
	readfile();
	system("cls");
	printf("-------------------------------------\n");
    printf("           6.学生信息输出            \n");
    printf("-------------------------------------\n");
    printf("请输入输出模式:(填写数字)\n"); 
    printf("1.成绩从高到低\n"); 
    printf("2.成绩从低到高\n");
    printf("3.按姓名首字母排序\n");
    printf("4.按学号大小排序\n");
    printf("-------------------------------------\n");
    scanf("%d", &choice);
    
	switch(choice)
	{
		case 1 : htl();
			output("从高到低排序的成绩单.txt");
			break;
		case 2 : lth();
			output("从低到高排序的成绩单.txt");
			break;
		case 3 : namesort();
			output("按名称首字母排序的成绩单.txt");
			break;
		case 4 : idsort(); 
			output("按学号排序的成绩单.txt");
			break;				
	} 
}


void quitapp()                                      // Quitapp                     
{
	system("cls");
	printf("\n\n\n\n-------------------------------------\n");
    printf("       欢迎下次使用( ̄︶ ̄)↗      \n") ;
    printf("-------------------------------------\n\n\n\n"); 
	system("pause"); 
	exit(0);	
}   


void full()                                        // Add a new student
{
	int j;
	printf("(eg:XXXXXXX(学号) XXXXXXXXX(姓名) XXX XXX XXX XXX(各科成绩) )\n");  
    printf("注意:当前可以输入的科目个数数为%d\n", course); 
    for(j = 0; j < 18; j++)
	{
	    scanf("%c", &stu[n].id[j]);
	    if(stu[n].id[j] == ' ')
		{
			stu[n].id[j] = '\0';
			break;	
		} 
	}                                     
	for(j = 0; j < 10; j++)
	{
	    scanf("%c", &stu[n].name[j]);
	    if(stu[n].name[j] == ' ')
		{
			stu[n].name[j] = '\0';
			break;	
		} 
	}
	stu[n].sum = 0;
	for(j = 0; j < course; j++)
	{
		scanf("%f", &stu[n].score[j]);
		stu[n].sum = stu[n].sum	+ stu[n].score[j];
		stu[n].ave_stu = stu[n].sum / course;
	}
	n++; 
	printf("-------------------------------------\n"); 
    printf("      已将该同学信息增加到程序中     \n");
	printf("-------------------------------------\n");  
}


void eachcour()                                    // Add a new course                        
{
	printf("-------------------------------------\n"); 
	printf("      请在出现的名字后面填写\n      该同学的新增科目的成绩\n");	               
	printf("-------------------------------------\n"); 
	int i;
	for(i = 0; i < n;i++)
	{
		printf("%s ", stu[i].name);
		scanf("%f", &stu[i].score[course]);
		stu[i].sum = stu[i].sum	+ stu[i].score[course];
		stu[i].ave_stu = stu[i].sum / (course + 1); 
	}
	course++;
}


void showinfo(char str[4])                         // Show student information
{
	int i, j; 
	printf("-------------------------------------\n");
    printf("          学生成绩信息显示           \n");
    printf("-------------------------------------\n");
    printf("当前显示模式为%s\n", str); 
	printf("总排名    学号        姓名");
	for(j = 1; j < course; j++)
	{
		printf("%6d  ", j);
	} 
	printf("%6d", course);
    printf("      总分   平均分\n");
	printf("-------------------------------------\n"); 
    for(i = 0;i < n;i++)
    {
    	printf("\n%3d、", i + 1);
		printf(" %10s ", stu[i].id);
    	printf("%10s  ", stu[i].name);
    	for(j = 0; j < course; j++)
    	{
    		printf("%-7.2f ", stu[i].score[j]);
    	} 
    	printf("%-7.2f %-7.2f\n", stu[i].sum, stu[i].ave_stu);
    }
}


int findstu(char a[2])                             //Find student information
{
	int i, j, choise = 0, t = 0; 
	char ex[30] = {'\0'};
	printf("-------------------------------------\n"); 
	printf("  请选择查询类型:学号(1);姓名(2)\n");
	printf("-------------------------------------\n"); 
	scanf("%d", &choise);
	if(choise == 1)
	{
		again: printf("-------------------------------------\n"); 
		printf("    请输入需要%s学生信息的学号\n", a);
		printf("-------------------------------------\n"); 
		scanf("%s", ex);
		for(i = 0;i < n;i++)
		{
			if(strcmp(ex, stu[i].id) == 0)
			{
				break;
			}
		}
		if(i == n)
		{
			printf("-------------------------------------\n"); 
			printf(" 输入学生信息有误或不存在,请重新输入\n");
			goto again;
		} 
		else
		{
			return i;
		}
	}
	else if(choise == 2)
	{
		printf("-------------------------------------\n"); 
		printf("     请输入需要%s学生信息的姓名\n", a);
		printf("-------------------------------------\n"); 
		scanf("%s", ex);
		for(i = 0;i < n;i++)
		{
			
			if(strcmp(ex, stu[i].name) == 0)
			{
				break;
			}
		}
		if(i == n)
		{
			printf("-------------------------------------\n"); 
			printf(" 输入学生信息有误或不存在,请重新输入\n");
			goto again;
		} 
		else
		{
			return i;
		}
	}
}


void ave()                                        //Each courses` average score       
{
	printf("-------------------------------------\n");
	printf("         各个学科的平均分为\n"); 
	printf("-------------------------------------\n"); 
	int i, j;
	float sum[6] = {0};
	for(i = 0; i < course; i++)
	{
		for(j = 0;j < n;j++)
		{
			sum[i] = sum[i] + stu[j].score [i];
		}
	}
	for(i = 0; i < course; i++)
	{
		printf("%d.科目%d:%.2f\n", i + 1, i + 1, sum[i] / n);
	}
}


void sum()                                       // Each courses` sum    
{
	printf("-------------------------------------\n");
	printf("        各个学科的成绩总和为\n"); 
	printf("-------------------------------------\n"); 
	int i, j;
	float sum[6] = {0};
	for(i = 0; i < course; i++)
	{
		for(j = 0;j < n;j++)
		{
			sum[i] = sum[i] + stu[j].score [i];
		}
	}
	for(i = 0; i < course; i++)
	{
		printf("%d.科目%d:%.2f\n", i + 1, i + 1, sum[i] );
	}
} 


void max_()                                     // Each courses` maxscore  
{
	printf("-------------------------------------\n");
	printf("        各科最高分如下:\n");
	printf("-------------------------------------\n"); 
	int i, j, max = 0;
	float t;
	for(i = 0; i < course;i++)
	{
		max = 0;
		t = stu[0].score[i];
		for(j = 0; j < n; j++)
		{
			if(t < stu[j].score[i])
			{
				t = stu[j].score[i];
				max = j;
			}
		}
		printf("%d.科目%d的最高分是:%s %.2f\n", i + 1, i + 1, stu[max].name, stu[max].score[i]);
	}	
} 


void htl()                                     //High to low
{
	int i, j;
	float a[6];
	char t[30];
	for(i = 0; i < n;i++)
	{
		for(j = 0; j < n - i; j++)
		{
			if(stu[j].sum < stu[j + 1].sum )
			{
				temp = stu[j + 1];
				stu[j + 1] = stu[j];
    			stu[j] = temp;
			}
		}
	}
	for(i = 0;i < n;i++)
	{
		for(j = 0; j < n - i - 1;j++)
		{
			if (strcmp(stu[j].name, stu[j + 1].name) > 0 && stu[j].sum == stu[j + 1].sum)
			{
				temp = stu[j + 1];
				stu[j + 1] = stu[j];
    			stu[j] = temp;
			}
		}
	}
} 


void lth()                                     //Low to high  
{
	int i, j;
	float a[6];
	char t[30];
	for(i = 0; i < n;i++)
	{
		for(j = 0; j < n - i - 1; j++)
		{
			if(stu[j].sum > stu[j + 1].sum )
			{
				temp = stu[j + 1];
				stu[j + 1] = stu[j];
    			stu[j] = temp;
			}
		}
	}
	for(i = 0;i < n;i++)
	{
		for(j = 0; j < n - i - 1;j++)
		{
			if (strcmp(stu[j].name, stu[j + 1].name) > 0 && stu[j].sum == stu[j + 1].sum)
			{
				temp = stu[j + 1];
				stu[j + 1] = stu[j];
    			stu[j] = temp;
			}
		}
	}
}


void idsort()
{
	int i, j;
	for(i = 0;i < n;i++)
	{
		for(j = 0; j < n - i - 1;j++)
		{
			if (strcmp(stu[j].id, stu[j + 1].id) > 0 )
			{
				temp = stu[j];
				stu[j] = stu[j + 1];
    			stu[j + 1] = temp;
			}
		}
	}
}   


void namesort()                               // The first name sort 
{
	int i, j;
	for(i = 0;i < n;i++)
	{
		for(j = 0; j < n - i - 1;j++)
		{
			if (strcmp(stu[j].name, stu[j + 1].name) > 0 )
			{
				temp = stu[j + 1];
				stu[j + 1] = stu[j];
    			stu[j] = temp;
			}
		}
	}
}


void output(char name[])                       // Save information to file 
{
	int i, j;
	FILE *fp;
	fopen_s(&fp, name, "wt+");  
	fprintf(fp, "———————————学生成绩表——————————————\n");
    fprintf(fp, "总排名       学号         姓名");
	for(j = 1; j < course; j++)
	{
		fprintf(fp, "%9d  ", j);
	} 
	fprintf(fp, "%9d", course);
    fprintf(fp, "         总分      平均分\n"); 
    fprintf(fp, "——————————————————————————————\n");
	for(i = 0; i < n; i++)           
	{
		fprintf(fp, "\n%3d、", i + 1);
		fprintf(fp, " %10s ", stu[i].id);
    	fprintf(fp, "%10s ", stu[i].name);
    	for(j = 0; j < course; j++)
    	{
    		fprintf(fp, "%7.2f ", stu[i].score[j]);
    	} 
    	fprintf(fp, "%7.2f %7.2f\n", stu[i].sum, stu[i].ave_stu);
	} 
	fclose(fp); 
	printf("-------------------------------------\n");  
	printf("已将文件存入%s\n", name);
	printf("-------------------------------------\n"); 	
}  


void presents()                                // Each course earch present 
{
	int i, j, nine, eight, seven, six, fail, t;
	for(i = 0;i < course; i++)
	{
		t = 0;
	    nine = 0;
	    eight = 0;
		seven = 0;
		six = 0;
		fail = 0;
		for(j = 0;j < course;j++)
		{
			if(stu[j].score[i] > 100.00)
			{
				t = 1;
				break;
			}		
		}
	    for(j = 0;j < n; j++)
		{
			
			if(t == 1)
			{
				stu[j].score[i] = stu[j].score[i] / 1.50;	
		    }
			if(stu[j].score[i] <= 100.00 && stu[j].score[i] >= 90.00)
			{
				nine++;
			}
			else if(stu[j].score[i] < 90.00 && stu[j].score[i] >= 80.00)
			{
				eight++;
			}
			else if(stu[j].score[i] < 80.00 && stu[j].score[i] >= 70.00)
			{
				seven++;
			}
			else if(stu[j].score[i] < 70.00 && stu[j].score[i] >= 60.00)
			{
				six++;
			}
			else if(stu[j].score[i] < 60.00)
			{
				fail++;
			}
		}
		printf("-------------------------------------\n"); 	
		printf("%d、科目%d输出结果如下:\n", i + 1, i + 1);
		printf("90-100:优秀的人数为%3d    占比为%.2f\n", nine,  nine  / (float)n);
		printf("80-90: 良好的人数为%3d    占比为%.2f\n", eight, eight / (float)n);
		printf("70-80: 一般的人数为%3d    占比为%.2f\n", seven, seven / (float)n);
		printf("60-70: 及格的人数为%3d    占比为%.2f\n", six,   six   / (float)n);
		printf("0-60:  不及格的人数为%3d  占比为%.2f\n", fail,  fail  / (float)n);
		printf("-------------------------------------\n"); 
	}
}

void save()                                    // Save information to file   
{
	int i, j;
	htl();
	for(i = 0; i < n; i++)
    {
    	if(stu[i].id[0] == '\n')
    	{
			for(j = 0;j < 18;j++)
			{
				stu[i].id[j] = stu[i].id[j + 1];
			}
		}
    }
	FILE *fp;
	fopen_s(&fp, "内部文件.txt", "wt+");   
	fprintf(fp, "%d %d\n", n, course); 
	for(i = 0; i < n; i++)           
	{
		fprintf(fp, "%s %s ", stu[i].id, stu[i].name);
		for(j = 0; j < course;j++)
		{
			fprintf(fp, "%.2f ", stu[i].score[j]);	
		}
		fprintf(fp, "%.2f ", stu[i].sum);
		fprintf(fp, "%.2f\n", stu[i].ave_stu);
	}
	fclose(fp);  	
} 


void readfile()                                // Read file information       
{
	FILE *fpp;
    fopen_s(&fpp, "内部文件.txt", "r+");      
    int i, j;                 
	char t;  
	while (!feof(fpp))
	{	
	    fscanf_s(fpp, "%d%d", &n, &course);
	    fscanf_s(fpp, "%c", &t);
	    for(i = 0;i < n;i++)
	    { 
	    	for(j = 0; j < 18; j++)
	    	{
	    		fscanf_s(fpp, "%c", &stu[i].id[j]);
	    		if(stu[i].id[j] == ' ')
				{
					stu[i].id[j] = '\0';
					break;	
				} 
			}                                   
			for(j = 0; j < 10; j++)
	    	{
	    		fscanf_s(fpp, "%c", &stu[i].name[j]);
	    		if(stu[i].name[j] == ' ')
				{
					stu[i].name[j] = '\0';
					break;	
				} 
			}
			for(j = 0; j < course; j++)
			{
				fscanf_s(fpp, "%f", &stu[i].score[j]);		
			}
			fscanf_s(fpp, "%f", &stu[i].sum);
			fscanf_s(fpp, "%f\n", &stu[i].ave_stu);
		}	
    }
    for(i = 0; i < n; i++)
    {
    	if(stu[i].id[0] == '\n')
    	{
			for(j = 0;j < 18;j++)
			{
				stu[i].id[j] = stu[i].id[j + 1];
			}
		}
    }
	fclose(fpp); 
} 

  • 7
    点赞
  • 61
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值