C语言学生管理系统(C语言课程设计/精简版)

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


typedef struct student{
char name[10];
int num;
int score;
struct student* pnext;
}STU;






void input(STU* phead){
STU* node = NULL;
    node = (STU*)malloc(sizeof(STU));
node->pnext = NULL;
printf("请输入该同学的姓名\n");
scanf("%s",node->name);
printf("请输入该同学的学号\n");
scanf("%d",&node->num);
printf("请输入该同学的成绩\n");
scanf("%d",&node->score);
FILE* fp = fopen("e:\\Student_info.dat","a");
if(fp == NULL)
printf("文件打开失败\n"); 
if(phead->pnext == NULL){
phead->pnext = node;
fwrite(phead->pnext,sizeof(STU),1,fp);
}
else{
while(phead->pnext != NULL){
phead = phead->pnext;
}
phead->pnext = node;
fwrite(phead->pnext,sizeof(STU),1,fp);
}
fclose(fp);
}




void viewer(STU* phead){
FILE* fp = fopen("e:\\Student_info.dat","r");
STU* plist = NULL;
plist = (STU*)malloc(sizeof(STU));
plist->pnext = NULL;
fread(plist,sizeof(STU),1,fp);
if(fp == NULL){
printf("未找到数据文件\n");
Sleep(3000);
}
else{
while(feof(fp) == 0){
printf("该同学的姓名为: %s\n" , plist->name);
printf("该同学的学号为: %d\n" , plist->num);
printf("该同学的成绩为: %d\n" , plist->score);
printf("\n");
fread(plist,sizeof(STU),1,fp);
}
printf("请按任意键进行下一步操作\n");
getch(); 
}
}




void menu(){
printf("1.录入信息\n");
printf("2.查看信息\n");
printf("0.退出\n");
}




int main(int argc,char** argv){
system("color 1e");
int select;
STU* head = NULL;
head = (STU*)malloc(sizeof(STU));
head->pnext = NULL;
while(1){
system("cls");
menu();
printf("请输入您要选择的功能\n\n");
printf("您选择的功能是: \n");
scanf("%d",&select);
switch(select)
{
case 1: input(head);
break;
case 2: viewer(head);
break;
case 0: exit(1);
break;
default : printf("输入无效,请重新输入\n");
break;
}
}


posted @ 2018-03-29 18:10  IT蓝月  阅读(242)  评论(0编辑  收藏  举报
Live2D