📄 db.h
字号:
l = c->next;
pan = ' ';
if (n == 1) {
printf("\n");
printf("save database?(Y/N)\n");
scanf("%c",&pan);
if (pan == 'Y')
save_record();
printf("\n");
}
for (i = 1; i <= count; i++)
delete_it(&c,&l);
head_db = nil;
current = nil;
last_db = nil;
count = 0;
if (n == 1)
printf("database close\n");
}
}
void output_record (void)
{
int n,
i;
struct node *c,
*l;
if (head_db == nil)
printf("no record\n");
else {
n = 1; /*指针初始化*/
c = head_db;
l = head_db->next;
output_title();
for (i = 1; i <= count; i++) {
output_it(c,n);
n = n + 1;
c = l;
l = c->next;
}
}
}
void del_record(void)
{
int condition_code;
int i,
deleted_num;
/* long_c,long_d : (* UNDEFINED TYPE: longint *);
Error 4: type expected: ; */
/* UNDEFINED TYPE: longint */
int long_c,long_d;
int del_num;
num_range1 del_number;
char del_name[11];
char del_sex;
struct date del_birthdate;
num_range2 del_experience;
num_range2 del_force;
num_range2 del_smartness;
struct node *c_bak,
*l_bak;
condition_code = condition_select("del condition:"); /*PROTECT*/
c_bak = current;
l_bak = last_db;
switch (condition_code) {
case 1:
printf("\n");
printf("record:");
scanf("%d",&del_num);
if ((del_num >= 1) && (del_num <= count)) {
if (head_db != nil) {
current = nil;
last_db = nil; /*FIND NODE*/
for (i = 1; i <= del_num; i++) {
if (i == 1) {
current = head_db;
last_db = current->next;
}
else {
current = last_db;
last_db = current->next;
} /*IF*/
} /*FOR*/
delete_it(¤t,&last_db);
printf(" record %d delete\n",del_num);
}
else
printf("no record like u need\n");
}
else
printf("out record\n");
break; /*1*/
case 2:
printf("\n");
printf("no:");
scanf("%d",&del_number);
if ((del_number >= 1) && (del_number <= 1000)) {
if (head_db != nil) {
current = head_db;
last_db = current->next;
deleted_num = 0;
for (i = 1; i <= count; i++) {
if (current->number == del_number) {
delete_it(¤t,&last_db);
deleted_num = deleted_num + 1;
}
else {
current = last_db;
last_db = current->next;
} /*IF*/
} /*FOR*/
if (deleted_num != 0)
printf(" record %d delete\n",deleted_num);
else
printf("no record like u need\n");
}
else
printf("no record like u need\n");
}
else
printf("out record\n");
break; /*2*/
case 3:
printf("\n");
printf("name:");
gets(del_name);
if (head_db != nil) {
current = head_db;
last_db = current->next;
deleted_num = 0;
for (i = 1; i <= count; i++) {
if (strcmp(current->name,del_name) == 0) {
delete_it(¤t,&last_db);
deleted_num = deleted_num + 1;
}
else {
current = last_db;
last_db = current->next;
} /*IF*/
} /*FOR*/
if (deleted_num != 0)
printf(" record %d delete\n",deleted_num);
else
printf("no record like u need\n");
}
else
printf("out record\n");
break;
case 4:
printf("\n");
printf("sex:");
scanf("%c",&del_sex);
if (head_db != nil) {
current = head_db;
last_db = current->next;
deleted_num = 0;
for (i = 1; i <= count; i++) {
if ((current->sex == del_sex)) {
delete_it(¤t,&last_db);
deleted_num = deleted_num + 1;
}
else {
current = last_db;
last_db = current->next;
} /*IF*/
} /*FOR*/
if (deleted_num != 0)
printf(" record %d delete\n",deleted_num);
else
printf("no record like u need\n");
}
else
printf("out record\n");
break;
case 5:
printf("\n");
printf("birthday:");
scanf("%d%d%d",&del_birthdate.da_year,&del_birthdate.da_mon,
&del_birthdate.da_day);
if (head_db != nil) {
current = head_db;
last_db = current->next;
deleted_num = 0;
long_d = del_birthdate.da_year;
long_d = long_d * 100;
long_d = long_d + del_birthdate.da_mon;
long_d = long_d * 100;
long_d = long_d + del_birthdate.da_day;
for (i = 1; i <= count; i++) {
long_c = current->birthdate.da_year;
long_c = long_c * 100;
long_c = long_c + current->birthdate.da_mon;
long_c = long_c * 100;
long_c = long_c + current->birthdate.da_day;
if ((long_c == long_d)) {
delete_it(¤t,&last_db);
deleted_num = deleted_num + 1;
}
else {
current = last_db;
last_db = current->next;
}
} /*FOR*/
if (deleted_num != 0)
printf(" record %d delete\n",deleted_num);
else
printf("no record like u need\n");
}
else
printf("out record\n");
break;
case 6:
printf("\n");
printf("experience:");
scanf("%d",&del_experience);
if (head_db != nil) {
current = head_db;
last_db = current->next;
deleted_num = 0;
for (i = 1; i <= count; i++) {
if ((current->experience == del_experience)) {
delete_it(¤t,&last_db);
deleted_num = deleted_num + 1;
}
else {
current = last_db;
last_db = current->next;
} /*IF*/
} /*FOR*/
if (deleted_num != 0)
printf(" record %d delete\n",deleted_num);
else
printf("no record like u need\n");
}
else
printf("out record\n");
break;
case 7:
printf("\n");
printf("force:");
scanf("%d",&del_force);
if (head_db != nil) {
current = head_db;
last_db = current->next;
deleted_num = 0;
for (i = 1; i <= count; i++) {
if ((current->force == del_force)) {
delete_it(¤t,&last_db);
deleted_num = deleted_num + 1;
}
else {
current = last_db;
last_db = current->next;
} /*IF*/
} /*FOR*/
if (deleted_num != 0)
printf(" record %d delete\n",deleted_num);
else
printf("no record like u need\n");
}
else
printf("out record\n");
break;
case 8:
printf("\n");
printf("smartness:");
scanf("%d",&del_smartness);
if (head_db != nil) {
current = head_db;
last_db = current->next;
deleted_num = 0;
for (i = 1; i <= count; i++) {
if ((current->smartness == del_smartness)) {
delete_it(¤t,&last_db);
deleted_num = deleted_num + 1;
}
else {
current = last_db;
last_db = current->next;
} /*IF*/
} /*FOR*/
if (deleted_num != 0)
printf(" record %d delete\n",deleted_num);
else
printf("no record like u need\n");
}
else
printf("out record\n");
break;
default:
printf("delete error\n");
break;
} /*CASE*/
if (last_db != nil) {
current = c_bak;
last_db = l_bak;
}
}
void find_record (void)
{
int condition_code;
int i,
found_num;
/* long_c,long_f : (* UNDEFINED TYPE: longint *);
Error 4: type expected: ; */
/* UNDEFINED TYPE: longint */
int long_c,long_f;
struct node *c,
*l;
int find_num;
num_range1 find_number;
char find_name[11];
char find_sex;
struct date find_birthdate;
num_range2 find_experience;
num_range2 find_force;
num_range2 find_smartness;
condition_code = condition_select("find condition:");
switch (condition_code) {
case 1:
printf("\n");
printf("record:");
scanf("%d",&find_num);
if ((find_num >= 1) && (find_num <= count)) {
if (head_db != nil) {
c = nil;
l = nil;
found_num = 1; /*FIND NODE*/
for (i = 1; i <= find_num; i++) {
if (i == 1) {
c = head_db;
l = c->next;
}
else {
c = l;
l = c->next;
} /*IF*/
} /*FOR*/
output_title();
output_it(c,find_num);
printf("find %d\n",found_num);
}
else
printf("no record\n");
}
else
printf("out record\n");
break;
case 2:
printf("\n");
printf("no:");
scanf("%d",&find_number);
if (head_db != nil) {
c = head_db;
l = c->next;
found_num = 0;
output_title();
for (i = 1; i <= count; i++) {
if (c->number == find_number) {
output_it(c,i);
found_num = found_num + 1;
c = l;
c = c->next;
}
else {
c = l;
l = c->next;
} /*IF*/
} /*FOR*/
if (found_num != 0)
printf("find %d\n",found_num);
else
printf("no record\n");
}
else
printf("out record\n");
break;
case 3:
printf("\n");
printf("name:");
gets(find_name);
if (head_db != nil) {
c = head_db;
l = c->next;
found_num = 0;
output_title();
for (i = 1; i <= count; i++) {
if (strcmp(c->name,find_name) == 0) {
output_it(c,i);
found_num = found_num + 1;
c = l;
c = c->next;
}
else {
c = l;
l = c->next;
} /*IF*/
} /*FOR*/
if (found_num != 0)
printf("find %d\n",found_num);
else
printf("no record\n");
}
else
printf("out record\n");
break;
case 4:
printf("\n");
printf("sex:");
scanf("%c",&find_sex);
if (head_db != nil) {
c = head_db;
l = c->next;
found_num = 0;
output_title();
for (i = 1; i <= count; i++) {
if (c->sex == find_sex) {
output_it(c,i);
found_num = found_num + 1;
c = l;
c = c->next;
}
else {
c = l;
l = c->next;
} /*IF*/
} /*FOR*/
if (found_num != 0)
printf("find %d\n",found_num);
else
printf("no record\n");
}
else
printf("out record\n");
break;
case 5:
printf("\n");
printf("birthday:");
scanf("%d%d%d",&find_birthdate.da_year,&find_birthdate.da_mon,
&find_birthdate.da_day);
if (head_db != nil) {
c = head_db;
l = c->next;
found_num = 0;
output_title();
long_f = find_birthdate.da_year;
long_f = long_f * 100;
long_f = long_f + find_birthdate.da_mon;
long_f = long_f * 100;
long_f = long_f + find_birthdate.da_day;
for (i = 1; i <= count; i++) {
long_c = c->birthdate.da_year;
long_c = long_c * 100;
long_c = long_c + c->birthdate.da_mon;
long_c = long_c * 100;
long_c = long_c + c->birthdate.da_day;
if (long_c == long_f) {
output_it(c,i);
found_num = found_num + 1;
c = l;
c = c->next;
}
else {
c = l;
l = c->next;
}
} /*FOR*/
if (found_num != 0)
printf("find %d\n",found_num);
else
printf("no record\n");
}
else
printf("out record\n");
break;
case 6:
printf("\n");
printf("experience:");
scanf("%d",&find_experience);
if (head_db != nil) {
c = head_db;
l = c->next;
found_num = 0;
output_title();
for (i = 1; i <= count; i++) {
if (c->experience == find_experience) {
output_it(c,i);
found_num = found_num + 1;
c = l;
l = c->next;
}
else {
c = l;
l = c->next;
} /*IF*/
} /*FOR*/
if (found_num != 0)
printf("find %d\n",found_num);
else
printf("no record\n");
}
else
printf("out record\n");
break;
case 7:
printf("\n");
printf("force:");
scanf("%d",&find_force);
if (head_db != nil) {
c = head_db;
l = c->next;
found_num = 0;
output_title();
for (i = 1; i <= count; i++) {
if (c->force == find_force) {
output_it(c,i);
found_num = found_num + 1;
c = l;
l = c->next;
}
else {
c = l;
l = c->next;
} /*IF*/
} /*FOR*/
if (found_num != 0)
printf("find %d\n",found_num);
else
printf("no record\n");
}
else
printf("out record\n");
break;
case 8:
printf("\n");
printf("smartness:");
scanf("%d",&find_smartness);
if (head_db != nil) {
c = head_db;
l = c->next;
found_num = 0;
output_title();
for (i = 1; i <= count; i++) {
if (c->smartness == find_smartness) {
output_it(c,i);
found_num = found_num + 1;
c = l;
l = c->next;
}
else {
c = l;
l = c->next;
} /*IF*/
} /*FOR*/
if (found_num != 0)
printf("find %d\n",found_num);
else
printf("no record\n");
}
else
printf("out record\n");
break;
default:
printf("find error\n");
break;
} /*CASE*/
}
void sort_record (void)
{
int condition_code;
int i,
j;
int long_c,long_f;
struct node *c_bak,
*l_bak;
condition_code = condition_select("sort condition:");
switch (condition_code) {
case 1:
printf("record over\n");
break;
case 2:
if ((head_db != nil) && (head_db->next != nil)) {
c_bak = current;
l_bak = last_db; /*沉淀法排序*/
for (i = count - 1; i >= 1; i--) {
current = c_bak;
last_db = l_bak;
for (j = 1; j <= i; j++) {
if (current->number < current->front->number)
swap_it(¤t,&last_db,&c_bak,&l_bak);
current = current->front;
last_db = current->next;
}
}
current = c_bak;
last_db = l_bak;
}
printf("no over\n");
break;
case 3:
if ((head_db != nil) && (head_db->next != nil)) {
c_bak = current;
l_bak = last_db; /*沉淀法排序*/
for (i = count - 1; i >= 1; i--) {
current = c_bak;
last_db = l_bak;
for (j = 1; j <= i; j++) {
if (strcmp(current->name,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -