C语言学生成绩管理(文件读取和写入)


# include 
# include 
# include 

# include 
# include 

# define eps 1;

typedef struct
{
    char name[50];
    int num;
    int Chinese;
    int Math;
    int English;
    int sum;
}Node;

Node student[1000];

int n;

char text[50];

int cmp(const void *a, const void *b)
{
    return (*(Node *)b).sum > (*(Node *)a).sum?1:-1;
}

int cmpnum(const void *a, const void *b)
{
    return (*(Node *)a).num > (*(Node *)b).num?1:-1;
}

void showstudent()
{
	void menu();
    int i;
	printf(" \t姓名\t学号\t语文\t数学\t英语\t总分\n");
	for(i=0;istudent[j+1].num)
			{
				k=student[j].num;
				student[j].num=student[j+1].num;
				student[j+1].num=k;
				k=student[j].Chinese;
				student[j].Chinese=student[j+1].Chinese;
				student[j+1].Chinese=k;
				k=student[j].Math;
				student[j].Math=student[j+1].Math;
				student[j+1].Math=k;
				k=student[j].English;
				student[j].English=student[j+1].English;
				student[j+1].English=k;
				k=student[j].sum;
				student[j].sum=student[j+1].sum;
				student[j+1].sum=k;
				strcpy(a,student[j].name);
				strcpy(student[j].name,student[j+1].name);
				strcpy(student[j+1].name,a);
			}
		}
	}
	showstudent();
    getch();
    menu();
}

void sortsum()
{
	void menu();
    qsort(student, n, sizeof(Node), cmp);
    showstudent();
    getch();
    menu();
}

void searchnum(int number)
{
	void menu();
    int min = 0, max = n-1, mid;
    bool escape = false;
    qsort(student, n, sizeof(Node), cmpnum);
    while(min <= max)
    {
        mid = (min + max) / 2;
        if(student[mid].num > number)
        {
            max = mid - eps;
        }
        else if(student[mid].num < number)
        {
            min = mid + eps;
        }
        else
        {
            escape = true;
            printf("\t姓名\t学号\t语文\t数学\t英语\t总分\n");
            printf("\t%s\t%d\t%d\t%d\t%d\t%d\n", student[mid].name, student[mid].num, student[mid].Chinese, student[mid].Math, student[mid].English, student[mid].sum);
            break;
        }
    }
    if(!escape)
    {
        printf("\t查无此人");
    }
    getch();
    menu();
}

void searchname()
{ 
	void menu();
	int i;
	for(i=0;i=n)
	{
		printf("\t查无此人\n");
	}
    getch();
    menu();
}

void save()
{
	void menu();
    FILE *fp;
	fp=fopen("4.txt","w");
	int i;
	fprintf(fp, "\t姓名\t学号\t语文\t数学\t英语\t总分\n");
	for(i=0;i

你可能感兴趣的:(C语言)