/*
* teacher.c
*
* Created on: 2012-12-17
* Author: root
*/
#include"teacher.h"
FILE * stream;
int Tcount=0;
int num;//记录登录次数
char user[10];//储存用户名
void Tinitial (T_list t_list)
{
if ((stream = fopen("teach_info.dat", "r"))
== NULL)
{ fprintf(stderr,
"Cannot open output file.\n");
return ;
}
P_TEA p=(P_TEA)malloc (sizeof (TEA));//头节点//学生头节点
t_list->head=p;
t_list->size=0;
P_TEA p_s= t_list->head;
p=(P_TEA)malloc (sizeof (TEA));
memset(p,0,sizeof(TEA));
while (1){
fread( p,sizeof(TEA),1,stream);
Tcount++;
t_list->size++;
p_s->next=p;
p=(P_TEA)malloc (sizeof (TEA));//头节点//学生头节点
p_s = p_s->next;
if(feof(stream))
{
break;
}
}
t_list->tail=p_s;
free(p);
fclose(stream);
}
void tea_login(T_list t_list)
{
int i=1;//控制菜单
printf("\t+===============================================+\n");
printf("\t 学生信息管理系统 \n");
printf("\t+===============================================+\n");
while (i)
{
printf("请输入工号:");
char password[20];
scanf("%s",user);
printf("输入密码:");
scanf("%s",password);
int T=Tvalidate(user,password);
if (T==1)
{
puts("用户登录成功");
teacher(user,t_list);
return;
}
else if(T==0)
{
puts("抱歉,登录失败!");
i=0;//跳出循环
}
}
}
int Tvalidate(char *s1,char *s2)
{
char c1[10],c2[10];
if(num>3)
{
return 0;
}
if ((stream = fopen("teach_passwd.conf", "r"))
== NULL)
{ fprintf(stderr,
"Cannot open output file.\n");
return 0 ;
}
while (fscanf (stream,"%s%s",c1,c2)!=EOF)
{
if (strcmp(c1,s1)==0&&strcmp(c2,s2)==0)
return 1;
}
puts("用户名或密码错误");
num++;
fclose(stream);
return 2;
}
void teacher (char *c,T_list t_list)
{
int menu_choice = 0;
Flag:
printf("\t+===============================================+\n");
printf("\t 欢迎来到STMS,老师你好 \n");
printf("\t+================================================\n");
printf("\t* 1.查看个人信息 *\n");
printf("\t* 2.修改个人信息 *\n");
printf("\t* 3.查看修改学生成绩 *\n");
printf("\t* 4.注销保存 *\n");
printf("\t+===============================================+\n");
printf("\n");
printf("\t请您选择功能:");
scanf("%d",&menu_choice);
switch(menu_choice)
{
case 1:
tea_show( t_list);
goto Flag;
// case 2:
// case 3:
// case 4:
// case 5:
case 4:
tea_save( t_list);
return;
}
}
void print (T_list t_list)
{
P_TEA p_tea=t_list->head->next;
while(p_tea!=NULL)
{
printf("%s\t%s\t%s\t%s\t%d\t%s\n",p_tea->t_ID,p_tea->t_name,p_tea->t_passwd,p_tea->sex,p_tea->age,p_tea->cc);
p_tea=p_tea->next;
}
}
P_TEA read2(T_list t_list)
{
P_TEA p_s = t_list->head->next;
while (p_s!=NULL)
{
if(strcmp(user,p_s->t_ID)==0)
{
return p_s;
}
else p_s=p_s->next;
}
return NULL;
};
void tea_show(T_list t_list)
{
printf("\t+===============================================+\n");
printf("\t 你的个人信息: \n");
printf("\t+================================================\n");
P_TEA p_tea= read2(t_list);
printf("\t+ =====姓名======年龄======班级=====年级=====语文\n");
printf ("\t\t%s%10s%10s%10d%10s\n\n\n\n\n\n\n",p_tea->t_ID,p_tea->t_name,p_tea->sex,p_tea->age,p_tea->cc);
}
void tea_save(T_list t_list)
{
P_TEA p = t_list->head->next;
if((stream=fopen("teach_info.dat","w+"))==NULL)
{
perror("open error!");
exit(-1);
}
while(p!=NULL){
fwrite(p,sizeof(TEA),1,stream);
// fprintf (stream,"%d\t%s\t%s\t%d\t%d\t%d\n",p->S_ID,p->S_name,p->S_passwd,p->age,p->class_num,p->grade_num);
p=p->next;
}
fclose(stream);
}
teacher.c
最新推荐文章于 2025-06-25 20:34:39 发布
该系统用于管理教师信息,包括登录验证、个人信息查看与修改、成绩管理等功能。
809

被折叠的 条评论
为什么被折叠?



