You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

264 lines
4.9 KiB

6 years ago
#include<stdbool.h>
#include<limits.h>
#include<math.h>
#include<stdlib.h>
#include<conio.h>
#include<Windows.h>
#include<stdio.h>
#include<string.h>
unsigned int counts = 0;
/*<2A><EFBFBD><EFBFBD><E5B6A8>*/
typedef struct student {
char no[21];
char name[11];
bool fame;
unsigned short int age;
char oth[151];
struct student * next;
}student;
struct student * first = NULL;//<2F><>һ<EFBFBD><D2BB>
struct student * loc = NULL;//<2F><>ǰ(һ<><D2BB>ΪNULL)
bool del(char *);//ɾ<><C9BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool edit(char*);//<2F><EFBFBD><E0BCAD><EFBFBD><EFBFBD>
student * search_by_no(char *);//<2F><>ѧ<EFBFBD>Ų<EFBFBD><C5B2><EFBFBD>
void search_by_name(char *);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool check_password(void);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void run(void);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
bool load(void);//<2F><><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
void fgets_nn(char * , int, FILE *);//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>з<EFBFBD><D0B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>char*<2A><><EFBFBD><EFBFBD>
bool check_no(char *);//<2F><><EFBFBD><EFBFBD>ѧ<EFBFBD><D1A7><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>ͻ
int main() {
run();
system("pause");
return 0;
}
bool del(char * no) {
student *ed = search_by_no(no);
if (ed == NULL)
return false;
student temp;
if (ed == first) {
temp = *first;
free(first);
first = temp.next;
return true;
}
student *lu = first;
while (lu->next != NULL) {
if (strlen(lu->next->no) == strlen(no) && !strcmp(lu->next->no, no)) {
break;
}
lu = lu->next;
}
temp = *lu->next;
free(lu->next);
lu->next = temp.next;
counts--;
save();
return true;
}
bool edit(char * no) {
student *l = search_by_no(no);
if (l == NULL)
return false;
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD>:\n");
while (1) {
char no_temp[21];
fgets_nn(no_temp, 21, stdin);
if (!strcmp(no_temp, "\0")) {
printf("ѧ<EFBFBD>Ų<EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>:\n");
continue;
}
if (!(strlen(l->no) == strlen(no_temp) && !strcmp(l->no, no_temp)))
if (!check_no(no_temp))
printf("ѧ<EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD><EFBFBD><EFBFBD>!\n");
else {
int i=0;
for ( i = 0; i < 21; i++)
l->no[i] = no_temp[i];
break;
}
else
break;
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
do {
fgets_nn(l->name, 11, stdin);
} while (!strcmp(l->name, "\0"));
while (1) {
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>(1.<2E><> 2.Ů):\n");
char t = getch();
if (t == '1') {
l->fame = true;
break;
}
else if (t == '2') {
l->fame = false;
break;
}
else {
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ\n");
continue;
}
}
while (1) {
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
if (scanf("%hd", &l->age) != 1) {
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ\n");
while (getchar() != '\n')continue;
continue;
}
break;
}
printf("<EFBFBD><EFBFBD>ע:\n");
while (getchar() != '\n')continue;
fgets_nn(l->oth, 151, stdin);
save();
return true;
}
student * search_by_no(char * no) {
student *l = first;
while (l != NULL) {
if (strlen(l->no) == strlen(no) && !strcmp(l->no, no)) {
return l;
}
l = l->next;
}
return NULL;
}
void search_by_name(char * name) {
student *l = first;
unsigned int c = 0;
system("cls");
while (l != NULL) {
if (strlen(l->name) == strlen(name) && !strcmp(l->name, name)) {
print_1(l);
printf("\n");
c++;
}
l = l->next;
}
if (c == 0) {
printf("δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>!\n");
}
else {
printf("\n<EFBFBD>Ѽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>%d<><64><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ%s<><73>ѧ<EFBFBD><D1A7>\n\n", c, name);
}
}
void run(void) {
int n=3;
while (n--) {
if (check_password()) {
load();
show_menu();
}
else if(n!=0){
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><EFBFBD><E3BBB9>%d<>λ<EFBFBD><CEBB><EFBFBD>!\n",n);
}
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֤ʧ<EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD>˳<EFBFBD>ϵͳ\n");
exith();
}
bool check_password(void) {
FILE * password;
password = fopen("password", "r");
if (password == NULL) {
printf("<EFBFBD><EFBFBD>һ<EFBFBD>ν<EFBFBD><EFBFBD><EFBFBD>ϵͳ,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<28>16λ,<2C><><EFBFBD><EFBFBD>6λ):\n");
password = fopen("password", "w");
system("attrib password +s +h +r");
char pw[17];
char pw2[17];
while (1) {
fgets_nn(pw, 17, stdin);
if (strlen(pw) < 6) {
system("cls");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>6λ:\n");
continue;
}
system("cls");
printf("<EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
fgets_nn(pw2, 17, stdin);
if (strcmp(pw, pw2)||(strlen(pw)!=strlen(pw2))) {
system("cls");
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD>ϴ<EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
continue;
}
break;
}
fprintf(password, "%s", pw);
fclose(password);
system("cls");
return true;
}
char pw[17];
fgets_nn(pw, 17, password);
if (feof(password)) {
fclose(password);
system("attrib password -s -h -r");
remove("password");
return check_password();
}
printf("<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>:\n");
char pwi[17];
fgets_nn(pwi, 17, stdin);
system("cls");
if (!strcmp(pw, pwi))
return true;
else
return false;
}
bool load(void) {
FILE * data;
data = fopen("data", "r");
if (data == NULL)
return false;
student temp;
while (1) {
fgets_nn(temp.no, 21, data);
if (feof(data)){
break;
}
fgets_nn(temp.name, 11, data);
fscanf(data, "%hhu", &temp.fame);
fscanf(data, "%hd", &temp.age);
fgetc(data);//ȥ<><C8A5><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>\n
fgets_nn(temp.oth, 151, data);
creat(temp);
counts++;
}
fclose(data);
return true;
}
void fgets_nn(char *buffer, int max, FILE * file) {
fgets(buffer, max, file);
int i=0;
for (i = 0; i < max; i++) {
if (buffer[i] == '\n') {
buffer[i] = '\0';
return;
}
}
}
bool check_no(char * no) {
student *l = first;
while (l != NULL) {
if (strlen(l->no) == strlen(no) && !strcmp(l->no, no)) {
return false;
}
l = l->next;
}
return true;
}