本篇博文用来记录学生头/教师文件建立以及结构体链表创建及链表相关操作

首先是头文件的建立

头文件包含学生结构体以及链表结构

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语言之一个简单的《学生教师管理系统》小结记录(二)的更多相关文章

  1. 【python免费代码】设计一个简单的学生信息管理系统

    文章目录 前言 一.理解 二.部分截图展示 三.代码 四.总结 前言 设计一个简单的学生信息管理系统,实现以下功能(bug) : 录入学生信息,信息以文件方式存储 以学生学号或者学生姓名为条件查询该学 ...

  2. PHP实现简单的学生信息管理系统(web版)

    (∩_∩) 1.概述 学了php的一些基础,包括HTML,php,pdo,mysql操作等,一直都没有将它们有机结合.最近写了一个简单的网页版学生信息管理系统,前台用HTML,脚本用到了JavaScr ...

  3. 【学生成绩管理系统】 大二c语言作业

    几年前写的了,只能在命令行窗口运行,虽然比较挫,还是有一定参考价值... #include <cstdio> #include <conio.h> #include <i ...

  4. C++ 简单的学生信息管理系统

    // // main.cpp // 2013-7-17作业1 // // Created by 丁小未 on 13-7-17. // Copyright (c) 2013年 dingxiaowei. ...

  5. C语言练手自己编写学生成绩管理系统

    #include<stdio.h> #include<stdlib.h> /*定义学生结构体*/ struct Student { ]; ]; float Mark1; flo ...

  6. Java实现简单的学生成绩管理系统

    ScoreInformation.java import java.util.Scanner; class ScoreInformation {    private String stunumber ...

  7. 学生信息管理系统.cpp(大二上)

      #include<iostream> #include<fstream> #include<string> #include<iomanip> #i ...

  8. 【C语言期末实训】学生学籍管理系统

    目录: 一,设计要求 ,总体要求: ,具体功能: 二,设计框架 三,程序代码 ,声明函数和头文件 ,声明结构体 ,声明全局变量 ,主体启动函数 ,主菜单函数 ,创建学生档案函数 ,编辑学生档案函数 , ...

  9. 程序阅读:简单C++学生信息管理系统

    课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [程序阅读]阅读并执行以下的程序,找出当中出现 ...

随机推荐

  1. logstash数据迁移

    logstash是一个非常强大的数据迁移工具.这里主要记录今天使用到的几个简单用法. 其中比较需要注意的是 迁移到elasticsearch的时候,output 的 elasticsearch 中的 ...

  2. SQL FIND_IN_SET() 判断某一个数是否存在于数据表某个以逗号分隔开字段数据中

    数据表中的字段存储的是以逗号分隔开的字符串, 例如 (1,2,6,8) 以前不知道这个用法, 碰到比如 8 是否包含在改字符串里面只能一个个取出来, 然后解析成数组,再判断是否在该数组中,效率极低: ...

  3. 记一次 vmware ESXI 升级

    旧服务器的esxi版本为 60(6765062),计划安装成为最新版 的为ESXI 60  (14513180),中间波折遇坑多次,现记录如下: 一.开启ESXI的SSH 访问权限(可以通过按F2进入 ...

  4. JavaSE基础(五)--Java运算符

    Java 运算符 计算机的最基本用途之一就是执行数学运算,作为一门计算机语言,Java也提供了一套丰富的运算符来操纵变量.我们可以把运算符分成以下几组: 算术运算符 关系运算符 位运算符 逻辑运算符 ...

  5. js函数(5)

    函数属性方法和构造函数 length属性 函数体中,arguments.length表示传入函数的实参个数. prototype属性 指向一个对象的引用 call方法和apply方法 看作是某个对象的 ...

  6. NLP文本清理时常用的python小函数

    # coding = utf-8 import re 1. 清理杂七杂八字符 ''' [a-zA-Z0-9] 字母数字 [\u4e00-\u9fa5] 汉字的utf-8 code范围 ''' # 保留 ...

  7. [CF1010D]Mars Over_位运算性质

    Mars rover 题目链接:http://codeforces.com/problemset/problem/1010/D 数据范围:略. 题解: 因为每次只改一个,改完之后改回去,这个性质很重要 ...

  8. [转帖]关于 /dev/urandom 的流言终结 | Linux 中国

    关于 /dev/urandom 的流言终结 | Linux 中国 2019年05月05日 14:03:52 技术无边 阅读数 202   版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权 ...

  9. HanLP分词工具中的ViterbiSegment分词流程

    本篇文章将重点讲解HanLP的ViterbiSegment分词器类,而不涉及感知机和条件随机场分词器,也不涉及基于字的分词器.因为这些分词器都不是我们在实践中常用的,而且ViterbiSegment也 ...

  10. Kafka 原理

    消息队列内部实现原理 两种消息传输方式 Kafka kafka 简介 kafka 集群角色 Kafka 工作流程分析 Kafka 生产过程分析 写入方式 分区(partition) 副本(replic ...