/* * student.h * * Created on: 2012-11-26 * Author: root */#ifndef STUDENT_H_#define STUDENT_H_#include "subject.h"#include <stdio.h>#include <string.h>#include <stdlib.h>#include <unistd.h>typedef struct student_info{ int S_ID; char S_name[32];char S_passwd[32];char sex[5]; int age; int class_num;int grade_num; int score_yuwen;int score_yingyu;int score_C;int score_sx;int score_rj;//float total; int rank;struct student_info *next;struct student_info *ptr;}* P_STU,STU;typedef struct s_liss{struct student_info * head;int size;struct student_info * tail;}*S_list,Slist;void student();int add_Stu();int del_S_ID();//添加学生的信息:(学号不得重复)int del_S_name();//姓名删除(如果重名,打印出所有的同名的学生信息)void stu_show_stu(int ss,S_list s_list);void stu_change_password(int ss,S_list s_list);void subject_choose();P_STU read1(int ss,S_list s_list);void Stu_save(S_list s_list);void quit();int validate(int s1,char *s2);void initial(S_list s_list);void stu_login(S_list s_list);#endif /* STUDENT_H_ */
student.c#include "student.h"#include"string.h"#define max 100static int count=0;//记录多少个学生int num=0;//记录登录次数FILE * stream; void initial(S_list s_list) { if ((stream = fopen("xueshengxinxi", "r")) == NULL) { fprintf(stderr, "Cannot open output file.\n"); return ; } P_STU p=(P_STU)malloc (sizeof (STU));//头节点 s_list->head=p; s_list->size=0; P_STU p_s= s_list->head; p=(P_STU)malloc (sizeof (STU)); while (fscanf (stream,"%d%s%s%d%s%d%d%d%d%d%d%d",&p->S_ID,p->S_name,p->S_passwd,&p->age,p->sex,&p->class_num,&p->grade_num,&p->score_yuwen,&p->score_yingyu,&p->score_C,&p->score_sx,&p->score_rj)!=EOF) { count++; s_list->size++; p_s->next=p; p=(P_STU)malloc (sizeof (STU));//头节点//学生头节点 p_s = p_s->next; } s_list->tail=p_s; free(p); fclose(stream); } void stu_login(S_list s_list) { int i=1;//控制菜单 printf("\t+===============================================+\n"); printf("\t 学生信息管理系统 \n"); printf("\t+===============================================+\n"); while (i) { printf("请输入学号:"); int id; char password[20]; scanf("%d",&id); printf("输入密码:"); scanf("%s",password); int T=validate(id,password); if (T==1) { puts("用户登录成功"); student(id,s_list); return; } else if(T==0) { puts("抱歉,登录失败!"); i=0;//跳出循环 } } } int validate(int s1,char *s2) { int id ; char cc[10]; if(num>3) { return 0; } if ((stream = fopen("stu_passwd.conf", "r")) == NULL) { fprintf(stderr, "Cannot open output file.\n"); return 0 ; } while (fscanf (stream,"%d%s",&id,cc)!=EOF) { if (s1==id&&strcmp(cc,s2)==0) return 1; } puts("用户名或密码错误"); num++; fclose(stream); return 2; }void student(int ss,S_list s_list ){int menu_choice = 0;Flag:printf("\t+===============================================+\n");printf("\t 学生信息管理系统 \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");// system("CLS");printf("\t请您选择功能:");scanf("%d",&menu_choice);switch(menu_choice){case 1: printf("\t您将查看您的信息!\n");stu_show_stu( ss, s_list);goto Flag;break;case 2: printf("\t您将修改您的个人密码!\n");stu_change_password( ss, s_list);goto Flag;break;case 3: subject_choose(); break;case 4: Stu_save( s_list);printf("\t注销成功,感谢您的使用\n");return;break;default:printf("\t您的选择有误,系统即将恢复,请重新选择!");goto Flag;}return ;}void stu_show_stu(int ss,S_list s_list){ printf("\t+===============================================+\n");printf("\t 你的个人信息: \n");printf("\t+================================================\n");P_STU p_stu= read1( ss, s_list);printf("\t+ =====姓名======年龄======班级=====年级=====语文=====英语=====C语言===数据结构===软件工程=====\n"); printf ("\t\t%s%10d%10d%10d%10d%10d%10d%10d%10d\n\n\n\n\n\n\n",p_stu->S_name,p_stu->age,p_stu->class_num,p_stu->grade_num,p_stu->score_yuwen,p_stu->score_yingyu,p_stu->score_C,p_stu->score_sx,p_stu->score_rj);};P_STU read1(int ss,S_list s_list){P_STU p_s = s_list->head->next;while (p_s!=NULL){ if(p_s->S_ID==ss) { return p_s; } else p_s=p_s->next;}return NULL;};void stu_change_password(int ss,S_list s_list){P_STU p_s = s_list->head->next;char s1[10],s2[10],s3[10];while (p_s!=NULL){ if(p_s->S_ID==ss) { puts("请输入原始密码"); scanf("%s",s1); puts("请输入新密码"); scanf("%s",s2); puts("请输入确认密码"); scanf("%s",s3); strcpy( p_s->S_passwd,s3); Stu_save( s_list); puts("密码修改成功"); return ; } else p_s=p_s->next;}}void Stu_save(S_list s_list){P_STU p = s_list->head->next;if((stream=fopen("stu_info.dat","w+"))==NULL){perror("open error!");exit(-1);} while(p!=NULL){ fwrite(p,sizeof(STU),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);}void subject_choose(){}student.h