功能
读取文件中关于学生姓名、专业、成绩等信息,计算其总成绩和各专业的学生数、平均成绩,并输出。
效果
读取文件:
小红 通信 84 88 84
小明 通信 77 65 58
张三 通信 89 93 95
李四 软件 88 91 94
钱五 软件 95 49 98
王五 网络 71 94 88
大明 网络 45 54 45
程序运行结果:
源代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>
#define IsCommu(x) (strcmp((x)->major, "通信") == 0) //利用宏判断专业类型
#define IsNet(x) (strcmp((x)->major, "网络") == 0)
#define IsSoft(x) (strcmp((x)->major, "软件") == 0)
struct student //存放学生数据的结构体
{
char name[100];
char major[100];
int eng;
int alg;
int c;
int sum;
} *p = NULL;
struct calc //存放专业统计数据的结构体
{
char major[100];
int snum;
int avg;
} Commu = {
"通信", 0, 0}, Net = {
"网络", 0, 0}, Soft = {
"软件", 0, 0};
int ReadStudentInfo(const char *filename) //打开文件,读取数据
{
int sum = 0, i;
char name[100]