c语言之一个简单的《学生教师管理系统》小结记录(二)
本篇博文用来记录学生头/教师文件建立以及结构体链表创建及链表相关操作
首先是头文件的建立
头文件包含学生结构体以及链表结构
1、学生结构体建立
/****定义学生信息******/ typedef struct studentInfo
{
int ID;
char name[];
char password[];
int age;
int classes;
char sex;
float math;
float chinese;
float clanguage;
}StuInfo;
2、链表结构建立
/*定义链表结构*/
typedef struct studentNode
{
struct studentInfo data;
struct studentNode *pNext;
}Node;
3、函数声明
/*创建链表结构并且申请空间*/
Node* makeNode(); /*学生信息初始化*/
StuInfo initData(); /*头插法*/
void headInsert(Node *pHead); /*循环处理,将节点的数据域写入文件*/
void writeToFile(Node *pHead); /*遍历链表*/
void showList(Node *pHead); /*从文件中读取链表信息*/
Node* readFromFile(Node *pHead); /*查找学生*/
Node* findnode(Node *pHead, const int ID); /*录入查重*/
Node* findstu(Node *pHead, const int ID); /*按班级遍历链表*/
void showClassList(Node *pHead, int classes); /*按总成绩显示排序*/
void showClassSortList(Node *pHead, int classes); /*修改学生信息初始化*/
StuInfo modinitData();
4、整个头文件
#ifndef __STUDENT_H_
#define __STUDENT_H_ #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h> #define STU_LEN sizeof(StuInfo)
#define NODE_LEN sizeof(Node) /****定义学生信息******/ typedef struct studentInfo
{
int ID;
char name[];
char password[];
int age;
int classes;
char sex;
float math;
float chinese;
float clanguage;
}StuInfo; /*定义链表结构*/
typedef struct studentNode
{
struct studentInfo data;
struct studentNode *pNext;
}Node; /*创建链表结构并且申请空间*/
Node* makeNode(); /*学生信息初始化*/
StuInfo initData(); /*头插法*/
void headInsert(Node *pHead); /*循环处理,将节点的数据域写入文件*/
void writeToFile(Node *pHead); /*遍历链表*/
void showList(Node *pHead); /*从文件中读取链表信息*/
Node* readFromFile(Node *pHead); /*查找学生*/
Node* findnode(Node *pHead, const int ID); /*录入查重*/
Node* findstu(Node *pHead, const int ID); /*按班级遍历链表*/
void showClassList(Node *pHead, int classes); /*按总成绩显示排序*/
void showClassSortList(Node *pHead, int classes); /*修改学生信息初始化*/
StuInfo modinitData(); #endif
5、函数实现
/*创建链表节点*/
Node* makeNode()
{
Node *newnode = (Node *)malloc(NODE_LEN);//为新节点分配空间
if(NULL == newnode)//容错处理,如果分配失败再次申请空间
{
newnode = (Node *)malloc(NODE_LEN);
}
memset(&newnode->data, '\0', STU_LEN);
newnode->pNext = NULL;
return newnode;
}
/*学生信息初始化*/
StuInfo initData()
{
StuInfo userInfo;
Node *temp = makeNode();
Node *pHead = makeNode();
pHead = readFromFile(pHead);
memset(&userInfo, '\0', STU_LEN);
printf("\t\t\t➢ 请输入学号:");
scanf("%d",&userInfo.ID);
getchar();
temp = findstu(pHead,userInfo.ID);
while(temp != NULL)//防止学号重复
{
printf("\t\t\t\033[31m\033[1m学号重复,请重新录入\033[0m\033[33m\n");
printf("\n\t\t\t➢ 请输入学号:");
scanf("%d",&userInfo.ID);
getchar();
temp = findstu(pHead,userInfo.ID);
}
printf("\t\t\t➢ 请输入姓名:");
scanf("%s",userInfo.name);
getchar();
strncpy(userInfo.password,"",);//初始密码为000000
printf("\t\t\t➢ 请输入年龄:");
scanf("%d",&userInfo.age);
getchar();
printf("\t\t\t➢ 请输入班级:");
scanf("%d",&userInfo.classes);
getchar();
printf("\t\t\t➢ 请输入性别:");
scanf("%c",&userInfo.sex);
getchar();
printf("\t\t\t➢ 请输入数学成绩:");
scanf("%f",&userInfo.math);
getchar();
printf("\t\t\t➢ 请输入语文成绩:");
scanf("%f",&userInfo.chinese);
getchar();
printf("\t\t\t➢ 请输入c语言成绩:");
scanf("%f",&userInfo.clanguage);
getchar();
temp = NULL;
pHead = NULL;
return userInfo;
}
/*修改学生信息*/
StuInfo modinitData(int stuID)//修改时学号可以和之前学号重复,但不能和其他人学号重复
{
StuInfo userInfo;
Node *temp = makeNode();
Node *pHead = makeNode();
pHead = readFromFile(pHead);
memset(&userInfo, '\0', STU_LEN);
printf("\t\t\t➢ 请输入学号:");
scanf("%d",&userInfo.ID);
getchar();
temp = findstu(pHead,userInfo.ID);
while((temp != NULL) && (userInfo.ID != stuID))
{
printf("\t\t\t\033[31m\033[1m学号重复,请重新录入\033[0m\033[33m\n");
printf("\n\t\t\t➢ 请输入学号:");
scanf("%d",&userInfo.ID);
getchar();
temp = findstu(pHead,userInfo.ID);
}
printf("\t\t\t➢ 请输入姓名:");
scanf("%s",userInfo.name);
getchar();
strncpy(userInfo.password,"",);//初始密码为000000
printf("\t\t\t➢ 请输入年龄:");
scanf("%d",&userInfo.age);
getchar();
printf("\t\t\t➢ 请输入班级:");
scanf("%d",&userInfo.classes);
getchar();
printf("\t\t\t➢ 请输入性别:");
scanf("%c",&userInfo.sex);
getchar();
printf("\t\t\t➢ 请输入数学成绩:");
scanf("%f",&userInfo.math);
getchar();
printf("\t\t\t➢ 请输入语文成绩:");
scanf("%f",&userInfo.chinese);
getchar();
printf("\t\t\t➢ 请输入c语言成绩:");
scanf("%f",&userInfo.clanguage);
getchar(); return userInfo;
}
/*链表操作之头插法*/
void headInsert(Node *pHead)
{
if(NULL == pHead)
{
perror("the list head is NULL!\n");
} Node *newnode = makeNode();
newnode->data = initData();//保存数据
newnode->pNext = pHead->pNext;//讲新的节点指针指向头结点的下一个节点
pHead->pNext = newnode;//头指针指向新节点
newnode = NULL;
}
/*遍历整个链表*/
void showList(Node *pHead)
{
if(NULL == pHead || NULL == pHead->pNext)
{
perror("the list is empty!");
return;
}
Node *temp = pHead->pNext;
printf("|-- ID --|---- name ----|");
printf("classes|-math-|chinese|clanguage|Total score|\n");
while(temp != NULL)
{
printf("| %-6d | %-12s | %-3d |",
temp->data.ID, temp->data.name, temp->data.classes);
printf("%-5.1f |%-5.1f | %-5.1f | %-5.1f |\n",
temp->data.math, temp->data.chinese,temp->data.clanguage,temp->data.math+temp->data.chinese+temp->data.clanguage);
temp = temp->pNext;//指向下一个节点
}
temp = NULL;
}
//按班级遍历链表
void showClassList(Node *pHead, int classes)
{
if(NULL == pHead || NULL == pHead->pNext)
{
perror("the list is empty!");
return;
}
Node *temp = pHead->pNext;
printf("|-- ID --|---- name ----|");
printf("classes|-math-|chinese|clanguage|Total score|\n");
while(temp != NULL)
{
if(classes == temp->data.classes)
{
printf("| %-6d | %-12s | %-3d |",
temp->data.ID, temp->data.name, temp->data.classes);
printf("%-5.1f |%-5.1f | %-5.1f | %-5.1f |\n",
temp->data.math, temp->data.chinese,temp->data.clanguage,temp->data.math+temp->data.chinese+temp->data.clanguage);
}
temp = temp->pNext;
}
temp = NULL;
}
//按总成绩显示排序
void showClassSortList(Node *pHead, int classes)
{
if(NULL == pHead || NULL == pHead->pNext)
{
perror("the list is empty!");
return;
}
Node *temp = pHead->pNext;
printf(" ✈ ✈ ✈ ✈ ✈ ✈ ✈ ✈ ✈ %d班成绩排名一览✈ ✈ ✈ ✈ ✈ ✈ ✈ ✈ ✈\n\n",classes);
printf("| 姓名 | 学号 | 数学 | 语文 | C语言 | 总分 |\n");
while(temp != NULL)
{
if(classes == temp->data.classes)
{
printf("| %-12s | %-4d | %-5.1f | %-5.1f | %-5.1f | %-6.1f |\n",
temp->data.name, temp->data.ID,
temp->data.math, temp->data.chinese,temp->data.clanguage,
(temp->data.math + temp->data.chinese + temp->data.clanguage));
}
temp = temp->pNext;
}
temp = NULL;
}
//循环处理,将节点的数据域写入文件
void writeToFile(Node *pHead)
{
if(NULL == pHead || NULL == pHead->pNext)
{
perror("NO data to write...\n");
return;
}
FILE *fpw = fopen("student.txt", "w");//可读写方式
if(NULL == fpw)
{
perror("open file student,txt failed!\n");
return;
} Node *temp = pHead->pNext;
while(NULL != temp)//循环写入
{
fwrite(&temp->data, STU_LEN, , fpw);
temp = temp->pNext;
}
system("clear");
puts("========文件保存成功!==========");
fclose(fpw);//关闭文件
return;
}
//链表的读文件
Node* readFromFile(Node *pHead)//从文件中将数据读取并且建立一个链表
{
if(NULL == pHead)
{
perror("the head is NULL!");
return NULL;
} FILE *fpr = fopen("student.txt", "r");//以可读方式打开
if(NULL == fpr)
{
perror("Open file student.txt failed!");
return NULL;
} Node *newnode = NULL;//新建节点
StuInfo stuInfo;//
memset(&stuInfo, '\0', STU_LEN);//空间初始化
while(fread(&stuInfo, STU_LEN, , fpr) > )//边读文件边建立链表
{
newnode = makeNode();
newnode->data = stuInfo;
newnode->pNext = pHead->pNext;
pHead->pNext = newnode;
}
fclose(fpr);//关闭文件
return pHead;//返回链表的头结点
}
/*查找学生*/
Node* findnode(Node *pHead, const int ID)//用于登录时显示登录信息
{
Node *p = makeNode();
p = pHead;
while(p != NULL)
{
if(ID == p->data.ID)
break;
p = p->pNext;
}
if(p == NULL)
{
printf("ID输入错误或此学生信息未录入\n");
}
return p;
}
完整student.c
/*student.c*/ #include "student.h" #define STU_LEN sizeof(StuInfo)
#define NODE_LEN sizeof(Node)
/*void main()
{
Node *pHead = makeNode();
// for(int i = 0; i < 2; i++)
// {
// printf("=====第 %d 个学生的信息=====\n",i+1);
// headInsert(pHead);
// }
// writeToFile(pHead);
readFromFile(pHead);
showList(pHead);
}*/ /*创建链表节点*/
Node* makeNode()
{
Node *newnode = (Node *)malloc(NODE_LEN);//为新节点分配空间
if(NULL == newnode)//容错处理,如果分配失败再次申请空间
{
newnode = (Node *)malloc(NODE_LEN);
}
memset(&newnode->data, '\0', STU_LEN);
newnode->pNext = NULL;
return newnode;
} /*学生信息初始化*/
StuInfo initData()
{
StuInfo userInfo;
Node *temp = makeNode();
Node *pHead = makeNode();
pHead = readFromFile(pHead);
memset(&userInfo, '\0', STU_LEN);
printf("\t\t\t➢ 请输入学号:");
scanf("%d",&userInfo.ID);
getchar();
temp = findstu(pHead,userInfo.ID);
while(temp != NULL)//防止学号重复
{
printf("\t\t\t\033[31m\033[1m学号重复,请重新录入\033[0m\033[33m\n");
printf("\n\t\t\t➢ 请输入学号:");
scanf("%d",&userInfo.ID);
getchar();
temp = findstu(pHead,userInfo.ID);
}
printf("\t\t\t➢ 请输入姓名:");
scanf("%s",userInfo.name);
getchar();
strncpy(userInfo.password,"",);//初始密码为000000
printf("\t\t\t➢ 请输入年龄:");
scanf("%d",&userInfo.age);
getchar();
printf("\t\t\t➢ 请输入班级:");
scanf("%d",&userInfo.classes);
getchar();
printf("\t\t\t➢ 请输入性别:");
scanf("%c",&userInfo.sex);
getchar();
printf("\t\t\t➢ 请输入数学成绩:");
scanf("%f",&userInfo.math);
getchar();
printf("\t\t\t➢ 请输入语文成绩:");
scanf("%f",&userInfo.chinese);
getchar();
printf("\t\t\t➢ 请输入c语言成绩:");
scanf("%f",&userInfo.clanguage);
getchar();
temp = NULL;
pHead = NULL;
return userInfo;
} /*修改学生信息*/
StuInfo modinitData(int stuID)//修改时学号可以和之前学号重复,但不能和其他人学号重复
{
StuInfo userInfo;
Node *temp = makeNode();
Node *pHead = makeNode();
pHead = readFromFile(pHead);
memset(&userInfo, '\0', STU_LEN);
printf("\t\t\t➢ 请输入学号:");
scanf("%d",&userInfo.ID);
getchar();
temp = findstu(pHead,userInfo.ID);
while((temp != NULL) && (userInfo.ID != stuID))
{
printf("\t\t\t\033[31m\033[1m学号重复,请重新录入\033[0m\033[33m\n");
printf("\n\t\t\t➢ 请输入学号:");
scanf("%d",&userInfo.ID);
getchar();
temp = findstu(pHead,userInfo.ID);
}
printf("\t\t\t➢ 请输入姓名:");
scanf("%s",userInfo.name);
getchar();
strncpy(userInfo.password,"",);//初始密码为000000
printf("\t\t\t➢ 请输入年龄:");
scanf("%d",&userInfo.age);
getchar();
printf("\t\t\t➢ 请输入班级:");
scanf("%d",&userInfo.classes);
getchar();
printf("\t\t\t➢ 请输入性别:");
scanf("%c",&userInfo.sex);
getchar();
printf("\t\t\t➢ 请输入数学成绩:");
scanf("%f",&userInfo.math);
getchar();
printf("\t\t\t➢ 请输入语文成绩:");
scanf("%f",&userInfo.chinese);
getchar();
printf("\t\t\t➢ 请输入c语言成绩:");
scanf("%f",&userInfo.clanguage);
getchar(); return userInfo;
} /*链表操作之头插法*/
void headInsert(Node *pHead)
{
if(NULL == pHead)
{
perror("the list head is NULL!\n");
} Node *newnode = makeNode();
newnode->data = initData();//保存数据
newnode->pNext = pHead->pNext;//讲新的节点指针指向头结点的下一个节点
pHead->pNext = newnode;//头指针指向新节点
newnode = NULL;
} /*遍历整个链表*/
void showList(Node *pHead)
{
if(NULL == pHead || NULL == pHead->pNext)
{
perror("the list is empty!");
return;
}
Node *temp = pHead->pNext;
printf("|-- ID --|---- name ----|");
printf("classes|-math-|chinese|clanguage|Total score|\n");
while(temp != NULL)
{
printf("| %-6d | %-12s | %-3d |",
temp->data.ID, temp->data.name, temp->data.classes);
printf("%-5.1f |%-5.1f | %-5.1f | %-5.1f |\n",
temp->data.math, temp->data.chinese,temp->data.clanguage,temp->data.math+temp->data.chinese+temp->data.clanguage);
temp = temp->pNext;//指向下一个节点
}
temp = NULL;
} //按班级遍历链表
void showClassList(Node *pHead, int classes)
{
if(NULL == pHead || NULL == pHead->pNext)
{
perror("the list is empty!");
return;
}
Node *temp = pHead->pNext;
printf("|-- ID --|---- name ----|");
printf("classes|-math-|chinese|clanguage|Total score|\n");
while(temp != NULL)
{
if(classes == temp->data.classes)
{
printf("| %-6d | %-12s | %-3d |",
temp->data.ID, temp->data.name, temp->data.classes);
printf("%-5.1f |%-5.1f | %-5.1f | %-5.1f |\n",
temp->data.math, temp->data.chinese,temp->data.clanguage,temp->data.math+temp->data.chinese+temp->data.clanguage);
}
temp = temp->pNext;
}
temp = NULL;
} //按总成绩显示排序
void showClassSortList(Node *pHead, int classes)
{
if(NULL == pHead || NULL == pHead->pNext)
{
perror("the list is empty!");
return;
}
Node *temp = pHead->pNext;
printf(" ✈ ✈ ✈ ✈ ✈ ✈ ✈ ✈ ✈ %d班成绩排名一览✈ ✈ ✈ ✈ ✈ ✈ ✈ ✈ ✈\n\n",classes);
printf("| 姓名 | 学号 | 数学 | 语文 | C语言 | 总分 |\n");
while(temp != NULL)
{
if(classes == temp->data.classes)
{
printf("| %-12s | %-4d | %-5.1f | %-5.1f | %-5.1f | %-6.1f |\n",
temp->data.name, temp->data.ID,
temp->data.math, temp->data.chinese,temp->data.clanguage,
(temp->data.math + temp->data.chinese + temp->data.clanguage));
}
temp = temp->pNext;
}
temp = NULL;
} //循环处理,将节点的数据域写入文件
void writeToFile(Node *pHead)
{
if(NULL == pHead || NULL == pHead->pNext)
{
perror("NO data to write...\n");
return;
}
FILE *fpw = fopen("student.txt", "w");//可读写方式
if(NULL == fpw)
{
perror("open file student,txt failed!\n");
return;
} Node *temp = pHead->pNext;
while(NULL != temp)//循环写入
{
fwrite(&temp->data, STU_LEN, , fpw);
temp = temp->pNext;
}
system("clear");
puts("========文件保存成功!==========");
fclose(fpw);//关闭文件
return;
} //链表的读文件
Node* readFromFile(Node *pHead)//从文件中将数据读取并且建立一个链表
{
if(NULL == pHead)
{
perror("the head is NULL!");
return NULL;
} FILE *fpr = fopen("student.txt", "r");//以可读方式打开
if(NULL == fpr)
{
perror("Open file student.txt failed!");
return NULL;
} Node *newnode = NULL;//新建节点
StuInfo stuInfo;//
memset(&stuInfo, '\0', STU_LEN);//空间初始化
while(fread(&stuInfo, STU_LEN, , fpr) > )//边读文件边建立链表
{
newnode = makeNode();
newnode->data = stuInfo;
newnode->pNext = pHead->pNext;
pHead->pNext = newnode;
}
fclose(fpr);//关闭文件
return pHead;//返回链表的头结点
} /*查找学生*/
Node* findnode(Node *pHead, const int ID)//用于登录时显示登录信息
{
Node *p = makeNode();
p = pHead;
while(p != NULL)
{
if(ID == p->data.ID)
break;
p = p->pNext;
}
if(p == NULL)
{
printf("ID输入错误或此学生信息未录入\n");
}
return p;
} /*录入查重*/
Node* findstu(Node *pHead, const int ID)//不打印信息
{
Node *p = makeNode();
p = pHead;
while(p != NULL)
{
if(ID == p->data.ID)
break;
p = p->pNext;
}
return p;
}
6、教师相关函数类似,直接放代码
teacher.h
#ifndef __TEACHER_H_
#define __TEACHER_H_
/*teacher.h*/ #include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h> /****定义教师信息******/ typedef struct teacherInfo
{
int ID;//教师工号
char name[];
char password[];
int age;
int classes;
char sex;
char position[]; //班主任 head, 数学math 语文 chinese, C语言 clanguage;
}TeaInfo; /*定义教师链表结构*/
typedef struct teacherNode
{
struct teacherInfo data;
struct teacherNode *pNext;
}TeaNode; #define TEA_LEN sizeof(TeaInfo)
#define TEANODE_LEN sizeof(TeaNode) /*构建节点*/
TeaNode* makeTeaNode(); /*初始化教师信息*/
TeaInfo initTeaData(); /*教师头插法*/
void teaheadInsert(TeaNode *pHead); /*教师信息保存*/
void writeToTeaFile(TeaNode *pHead); /*教师信息遍历*/
void showTeaList(TeaNode *pHead); /*从文件中读取教师信息*/
TeaNode* readFromTeaFile(TeaNode *pHead); /*查找教师*/
TeaNode* findteanode(TeaNode *pHead, const int ID); /*录入查重*/
TeaNode* findtea(TeaNode *pHead, const int ID); /*修改初始化调用*/
TeaInfo modinitTeaData(); #endif
teacher.c
/*teacher.c*/ #include "teacher.h" #define TEA_LEN sizeof(TeaInfo)
#define TEANODE_LEN sizeof(TeaNode) /*void main()
{
TeaNode *pHead = makeTeaNode();
//for(int i = 0; i < 2; i++)
//{
// printf("=====第 %d 个教师的信息=====\n",i+1);
// teaheadInsert(pHead);
//}
//writeToTeaFile(pHead);
pHead = readFromTeaFile(pHead);
showTeaList(pHead);
}*/ /*申请空间*/
TeaNode* makeTeaNode()
{
TeaNode *newnode = (TeaNode *)malloc(TEANODE_LEN);
if(NULL == newnode)
{
newnode = (TeaNode *)malloc(TEANODE_LEN);
}
memset(&newnode->data, '\0', TEA_LEN);
newnode->pNext = NULL;
return newnode;
} /*教师信息初始化*/
TeaInfo initTeaData()
{
TeaInfo userInfo;
TeaNode *temp = makeTeaNode();
TeaNode *pTHead = makeTeaNode();
pTHead = readFromTeaFile(pTHead);
memset(&userInfo, '\0', TEA_LEN);
printf("\n\t\t\t➢ 请输入工号:");
scanf("%d",&userInfo.ID);
getchar();
temp = findtea(pTHead,userInfo.ID);
while(temp != NULL)
{
printf("\t\t\t\033[31m\033[1m工号重复,请重新录入\033[0m\033[33m\n");
printf("\n\t\t\t➢ 请输入工号:");
scanf("%d",&userInfo.ID);
getchar();
temp = findtea(pTHead,userInfo.ID);
}
printf("\n\t\t\t➢ 请输入姓名:");
scanf("%s",userInfo.name);
getchar();
strncpy(userInfo.password,"",);//初始密码为000000
printf("\n\t\t\t➢ 请输入年龄:");
scanf("%d",&userInfo.age);
getchar();
printf("\n\t\t\t➢ 请输入班级:");
scanf("%d",&userInfo.classes);
getchar();
printf("\n\t\t\t➢ 请输入性别:");
scanf("%c",&userInfo.sex);
getchar();
printf("\n\t\t\t➢ 请输入职位:");
scanf("%s",userInfo.position);
getchar();
return userInfo;
} /*修改初始化调用*/
TeaInfo modinitTeaData()
{
TeaInfo userInfo;
memset(&userInfo, '\0', TEA_LEN);
printf("\t\t\t➢ 请输入工号:");
scanf("%d",&userInfo.ID);
getchar();
printf("\t\t\t➢ 请输入姓名:");
scanf("%s",userInfo.name);
getchar();
strncpy(userInfo.password,"",);//初始密码为000000
printf("\t\t\t➢ 请输入年龄:");
scanf("%d",&userInfo.age);
getchar();
printf("\t\t\t➢ 请输入班级:");
scanf("%d",&userInfo.classes);
getchar();
printf("\t\t\t➢ 请输入性别:");
scanf("%c",&userInfo.sex);
getchar();
printf("\t\t\t➢ 请输入职位:");
scanf("%s",userInfo.position);
getchar();
return userInfo;
} /*教师头插法*/
void teaheadInsert(TeaNode *pHead)
{
if(NULL == pHead)
{
perror("the teacher list head is NULL!\n");
} TeaNode *newnode = makeTeaNode();
newnode->data = initTeaData();
newnode->pNext = pHead->pNext;
pHead->pNext = newnode;
newnode = NULL;
} /*遍历链表*/
void showTeaList(TeaNode *pHead)
{
if(NULL == pHead || NULL == pHead->pNext)
{
perror("the teacher list is empty!");
return;
}
TeaNode *temp = pHead->pNext;
int i = ;
printf("-- ID -- |---- name ----|-- password --|");
printf("-age-|classes|sex|--position--|\n");
while(temp != NULL)
{
printf("| %-6d | %-12s | %-12s |",
temp->data.ID, temp->data.name, temp->data.password);
printf(" %-3d | %-3d |%-3c| %-10s |\n",
temp->data.age,temp->data.classes, temp->data.sex, temp->data.position);
i++;
temp = temp->pNext;
}
temp = NULL;
return;
} //循环处理,将节点的数据域写入文件
void writeToTeaFile(TeaNode *pHead)
{
if(NULL == pHead || NULL == pHead->pNext)
{
perror("NO teacher data to write...\n");
return;
}
FILE *fpw = fopen("teacher.txt", "w");
if(NULL == fpw)
{
perror("open file teacher.txt failed!\n");
return;
} TeaNode *temp = pHead->pNext;
while(NULL != temp)
{
fwrite(&temp->data, TEA_LEN, , fpw);
temp = temp->pNext;
}
system("clear");
puts("========文件保存成功!==========");
fclose(fpw);
return;
} //链表的读文件
TeaNode* readFromTeaFile(TeaNode *pHead)
{
if(NULL == pHead)
{
perror("the teacher head is NULL!");
return NULL;
} FILE *fpr = fopen("teacher.txt", "r");
if(NULL == fpr)
{
FILE *fpr = fopen("teacher.txt", "w");
} TeaNode *newnode = NULL;
TeaInfo teaInfo;
memset(&teaInfo, '\0', TEA_LEN);
while(fread(&teaInfo, TEA_LEN, , fpr) > )
{
newnode = makeTeaNode();
newnode->data = teaInfo;
newnode->pNext = pHead->pNext;
pHead->pNext = newnode;
}
fclose(fpr);
return pHead;
} /*查找教师*/
TeaNode* findteanode(TeaNode *pHead, const int ID)
{
TeaNode *p = makeTeaNode();
p = pHead;
while(p != NULL)
{
if(ID == p->data.ID)
break;
p = p->pNext;
}
if(p == NULL)
{
printf("ID输入错误或此教师信息未录入\n");
}
return p;
} /*录入查重*/
TeaNode* findtea(TeaNode *pHead, const int ID)
{
TeaNode *p = makeTeaNode();
p = pHead;
while(p != NULL)
{
if(ID == p->data.ID)
break;
p = p->pNext;
}
return p;
}
所有执行模块函数在下一部分记录。。。。。
c语言之一个简单的《学生教师管理系统》小结记录(二)的更多相关文章
- 【python免费代码】设计一个简单的学生信息管理系统
文章目录 前言 一.理解 二.部分截图展示 三.代码 四.总结 前言 设计一个简单的学生信息管理系统,实现以下功能(bug) : 录入学生信息,信息以文件方式存储 以学生学号或者学生姓名为条件查询该学 ...
- PHP实现简单的学生信息管理系统(web版)
(∩_∩) 1.概述 学了php的一些基础,包括HTML,php,pdo,mysql操作等,一直都没有将它们有机结合.最近写了一个简单的网页版学生信息管理系统,前台用HTML,脚本用到了JavaScr ...
- 【学生成绩管理系统】 大二c语言作业
几年前写的了,只能在命令行窗口运行,虽然比较挫,还是有一定参考价值... #include <cstdio> #include <conio.h> #include <i ...
- C++ 简单的学生信息管理系统
// // main.cpp // 2013-7-17作业1 // // Created by 丁小未 on 13-7-17. // Copyright (c) 2013年 dingxiaowei. ...
- C语言练手自己编写学生成绩管理系统
#include<stdio.h> #include<stdlib.h> /*定义学生结构体*/ struct Student { ]; ]; float Mark1; flo ...
- Java实现简单的学生成绩管理系统
ScoreInformation.java import java.util.Scanner; class ScoreInformation { private String stunumber ...
- 学生信息管理系统.cpp(大二上)
#include<iostream> #include<fstream> #include<string> #include<iomanip> #i ...
- 【C语言期末实训】学生学籍管理系统
目录: 一,设计要求 ,总体要求: ,具体功能: 二,设计框架 三,程序代码 ,声明函数和头文件 ,声明结构体 ,声明全局变量 ,主体启动函数 ,主菜单函数 ,创建学生档案函数 ,编辑学生档案函数 , ...
- 程序阅读:简单C++学生信息管理系统
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [程序阅读]阅读并执行以下的程序,找出当中出现 ...
随机推荐
- 启动mongodb报错,无法连接mongodb
报错原因如下: MongoDB shell version v3.4.2 connecting to: mongodb://127.0.0.1:27017 --01T12:: W NETWORK [t ...
- Tracking of Features and Edges
目录 Joint Tracking of Features and Edges Joint Tracking of Features and Edges 1. LK光流 基本LK光流运动假设: \[ ...
- Facebook程序员跳楼事件:技术路线会越走越窄吗?
这是小川的第417次更新,第450篇原创 这几天有个刷屏的文章,讲的是Facebook有位程序员跳楼了,这位程序员的一些信息也"被曝光",比如年轻时是浙大的学霸,后来又赴美读硕,中 ...
- Python数据结构与语法
字典:Python字典是另一种可变容器模型,且可存储任意类型对象,如字符串.数字.元组.字典等其他容器模型:值可以取任何数据类型,但键必须是不可变的,如字符串,数字或元组:遍历字典时遍历的是键:访问v ...
- 如何制作红蓝3d电影(详细教程)
自20世纪初以来,电影制作人一直试图通过制作3D电影来利用我们的双眼.现在,由于大量相对实惠的3D电视,你可以享受电影院以外的额外空间 - 你自己拍摄的视频.对于大预算的电影,电影摄影师使用两个相连的 ...
- Vue CLI 3 如何自定义 js 的文件名
参考链接:https://blog.csdn.net/weixin_33979363/article/details/88742342
- CentOS 7 利用qemu模拟ARM vexpress A9开发板
听说qemu用于仿真arm很不错,今日就来试了一把.由于刚刚开始,了解的并不多.本文仅仅记录Qemu装载Linux kernel和busybox根文件系统的过程.后续将会深入了解仿真的其他内容. 先上 ...
- storm drpc分布式本地和远程调用模式讲解
一.drpc 的介绍 1.rpc RPC(Remote Procedure Call)—远程过程调用,它是一种通过网络从远程计算机程序上请求服务,而不需要了解底层网络技术的协议. 2.drpc drp ...
- redis单机连接池
一.配置文件 1. db.properties配置文件#IP地址 redis.ip = 127.0.0.1 #端口号 redis.port= #最大连接数 redis.max.total= #最大空闲 ...
- Flask-WTF的使用
Flask-WTF的使用 一.安装Flask-WTF Flask-WTF 对 WTForms 进行了封装使它能够在 Flask 框架中可以被调用,其中 Flask-WTF 的功能都是继承自 WTFor ...