C语言
这周C语言主要以课设为主,
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
struct date
{
int year;
int month;
int day;
};
typedef struct people
{
char name[10];
char card[20];
int age;
char sex[5];
struct date time;
char degree[10];
char place[10];
char phone[20];
struct people *next;
}PEOPLE;
PEOPLE * input_people(PEOPLE *head);
void display_people(PEOPLE *head);
void query_name_people(PEOPLE *head);
void query_card_people(PEOPLE *head);
void query_name_phone_people(PEOPLE *head);
void query_people(PEOPLE *head);
void change_people(PEOPLE* head);
void change_name_people(PEOPLE* head);
void change_card_people(PEOPLE* head);
int encrypt_people(char code1[]);
void save_people(PEOPLE *head);
//void* read_people(PEOPLE *head);
PEOPLE * delete_name_people(PEOPLE *head);
PEOPLE * delete_card_people(PEOPLE *head);
PEOPLE * delete_people(PEOPLE *head);
void insert_people(PEOPLE *head);
void statistics_place_people(PEOPLE *head);
void statistics_age_people(PEOPLE *head);
void statistics_sex_people(PEOPLE *head);
void statistics_people(PEOPLE *head);
void statistics_degree_people(PEOPLE *head);
void statistics_age_sex_people(PEOPLE *head);
void statistics_place_degree_people(PEOPLE *head);
PEOPLE *sort_people(PEOPLE *head);
PEOPLE *sort_age_add_people(PEOPLE *head);
PEOPLE *sort_age_less_people(PEOPLE *head);
PEOPLE *sort_degree_add_people(PEOPLE *head);
PEOPLE *sort_degree_less_people(PEOPLE *head);
int dl();
int judge();
void regist();
char reg_name[30]="",reg_pwd[10]="";
char on_name[30],on_pwd[10];
int main()
{
int id=1,flag=1;
while(id)
{
system("pause");
system("cls");
//输出界面
printf("\n\n\t\t\t管理系统\n\n");
printf("\t\t\t1:注册\n");
printf("\t\t\t2:登录\n");
printf("\t\t\t0:退出\n\n");
//输入功能编号
printf("\t\t请选择功能编号:");
scanf("%d",&id);
//判断
switch(id)
{
case 1:regist();break;
case 2:
if(judge()==1)
{
flag=dl();
}
break;
case 0:break;
default:
printf("\n\t\t您输入的功能编号有误,请重新输入!\n");
}
if(flag==0)
break;
}
PEOPLE *head=NULL;
int select=1;
while(select != 0)
{
system("cls");
printf(" !!!欢迎使用本系统!!!\n");
printf(" *******************************\n");
printf(" ** 新冠疫情管理系统 **\n");
printf(" ** **\n");
printf(" ** 1. 病患信息录入 **\n");
printf(" ** 2. 病患信息删除 **\n");
printf(" ** 3. 病患信息查询 **\n");
printf(" ** 4. 病患信息修改 **\n");
printf(" ** 5. 病患信息排序 **\n");
printf(" ** 6. 病患信息显示 **\n");
printf(" ** 7. 病患信息统计 **\n");
printf(" ** 8. 病患信息插入 **\n");
printf(" ** 9. 病患信息读取 **\n");
printf(" ** 10.病患信息存储 **\n");
printf(" ** **\n");
printf(" ** 0. 退出 **\n");
printf(" *******************************\n");
printf(" 请选择输入:");
scanf("%d",&select);
system("cls");
switch(select)
{
case 1:
head=input_people(head);
break;
case 2:
head=delete_people(head);
break;
case 3:
query_people(head);
break;
case 4:
change_people(head);
break;
case 5:
head=sort_people(head);
break;
case 6:
display_people(head);
break;
case 7:
statistics_people(head);
break;
case 8:
insert_people(head);
break;
/*case 9:
read_people(head);
break;*/
case 10:
save_people(head);
break;
default:
printf("输入错误,请重新输入");
break;
}
}
return 0;
}
PEOPLE * input_people(PEOPLE *head)
{
PEOPLE *p,*q;
p=(PEOPLE *)malloc(sizeof(PEOPLE));
printf(" 请录入病患信息\n");
printf(" 姓名:");
scanf("%s",p->name);
printf(" 性别:");
scanf("%s",p->sex);
printf(" 身份证号:");
scanf("%s",p->card);
printf(" 年龄:");
scanf("%d",&p->age);
printf(" 确诊日期:(注:输入格式 年.月.日)");
scanf("%d.%d.%d",&p->time.year,&p->time.month,&p->time.day);
while(p->time.month<=0||p->time.month>12||p->time.day<=0||p->time.day>31)
{
printf("\n 输入有误,请重新输入:");
scanf("%d.%d.%d",&p->time.year,&p->time.month,&p->time.day);
}
printf(" 患病情况:");
scanf("%s",p->degree);
printf(" 住址:");
scanf("%s",&p->place);
printf(" 电话号码:");
scanf("%s",p->phone);
p->next = NULL;
if(head==NULL)
head=p;
else
{
q=head;
while(q->next!=NULL)
q=q->next;
q->next = p;
}
return head;
}
//信息录入。
void display_people(PEOPLE *head)
{
PEOPLE *p;
if(head==NULL)
{
printf(" 目前尚未录入学生信息! 按任意键返回.\n");
getch();
return;
}
printf(" 学生信息如下:\n");
p=head;
while(p!=NULL)
{
printf(" 姓名:%s\n",p->name);
printf(" 性别:%s\n",p->sex);
printf(" 年龄:%d\n",p->age);
printf(" 身份证号:%s\n",p->card);
printf(" 确诊日期:%d.%d.%d\n",p->time.year,p->time.month,p->time.day);
printf(" 患病情况:%s",p->degree);
printf(" 住址:%s\n",p->place);
printf(" 电话号码:%s\n",p->phone);
p=p->next;
}
printf("\n 已全部显示,按任意键返回。\n");
getch();
return ;
}
//信息输出
void query_name_people(PEOPLE *head)
{
PEOPLE *p=head;
char num[20];
printf(" 请输入要查询病患的姓名:");
scanf("%s",num);
while(strcmp(p->name,num)!=0&&p!=NULL)
{
p=p->next;
}
if(p!=NULL)
{
printf(" 姓名:%s\n",p->name);
printf(" 性别:%s\n",p->sex);
printf(" 年龄:%d\n",p->age);
printf(" 身份证号:%s\n",p->card);
printf(" 确诊日期:%d.%d.%d\n",p->time.year,p->time.month,p->time.day);
printf(" 患病情况:%s\n",p->degree);
printf(" 住址:%s\n",p->place);
printf(" 电话号码:%s\n",p->phone);
}
else
printf(" 找不到姓名为%s的患者\n",num);
printf(" 按任意键继续。\n");
getch();
return ;
}
//以姓名查询
void query_card_people(PEOPLE *head)
{
PEOPLE *p=head;
char num[20];
printf(" 请输入要查询病患的身份证号:");
scanf("%s",num);
while(strcmp(p->card,num)!=0&&p->next!=NULL)
{
p=p->next;
}
if(p->next!=NULL)
{
printf(" 姓名:%s\n",p->name);
printf(" 性别:%s\n",p->sex);
printf(" 年龄:%d\n",p->age);
printf(" 身份证号:%s\n",p->card);
printf(" 确诊日期:%d.%d.%d\n",p->time.year,p->time.month,p->time.day);
printf(" 患病情况:%s\n",p->degree);
printf(" 住址:%s\n",p->place);
printf(" 电话号码:%s\n",p->phone);
}
else
printf(" 找不到身份证号为%s的患者\n",num);
printf(" 按任意键继续。");
getch();
return ;
}
//以身份证号查询
void query_people(PEOPLE *head)
{
int k;
printf(" *******************************\n");
printf(" ** 1. 姓名查询 **\n");
printf(" ** 2. 身份证号查询 **\n");
printf(" ** 3. 姓名—电话查询**\n");
printf(" ** 0. 返回 **\n");
printf(" *******************************\n");
printf(" 请选择查询方式 :");
while(1)
{
scanf("%d",&k);
if(k==1)
{
query_name_people(head);
}
else if(k==2)
{
query_name_people(head);
}
else if(k==3)
{
query_name_phone_people(head);
}
else if(k==0)
break;
else
printf(" 输入错误,请重新输入。\n");
}
}
void query_name_phone_people(PEOPLE *head)
{
PEOPLE *p=head;
char num[20],sum[20];
printf(" 请输入要查询病患的姓名:");
scanf("%s",num);
printf(" 请输入要查询病患的手机号码:");
scanf("%s",sum);
while(strcmp(p->card,num)!=0&&strcmp(p->phone,sum)!=0&&p->next!=NULL)
{
p=p->next;
}
if(p->next!=NULL)
{
printf(" 姓名:%s\n",p->name);
printf(" 性别:%s\n",p->sex);
printf(" 年龄:%d\n",p->age);
printf(" 身份证号:%s\n",p->card);
printf(" 确诊日期:%d.%d.%d\n",p->time.year,p->time.month,p->time.day);
printf(" 患病情况:%s\n",p->degree);
printf(" 住址:%s\n",p->place);
}
else
printf(" 找不到身份证号为%s且手机号为%s的患者\n",num,sum);
printf(" 按任意键继续。");
getch();
return ;
}
void save_people(PEOPLE *head)
{
FILE *fp;
PEOPLE *p;
if((fp=fopen("d://课设.txt","wt"))==NULL)
printf("Can not open the file!");
p=head;
while(p!=NULL)
{
fprintf(fp,"%s %s %d %s %d.%d.%d %s %s %s\n",p->name,p->sex,p->age,p->card,p->time.year,p->time.month,p->time.day,p->degree,p->place,p->phone);
p=p->next;
}
fclose(fp);
printf("存储完成\n");
system("pause");
system("cls");
}
void change_name_people(struct people* head)
{
PEOPLE *p=head;
if(head==NULL)
{
printf(" 未录入信息,按任意键返回\n");
getch();
return;
}
char num[20];
printf(" 请输入要修改病患的姓名:");
scanf("%s",num);
while(strcmp(p->name,num)!=0&& p!=NULL)
{
p=p->next;
}
if(p!=NULL)
{
int k=1;
printf(" \n1.姓名\n ");
printf(" 2.身份证号\n ");
printf(" 3.性别\n ");
printf(" 4.住址\n ");
printf(" 5.年龄\n ");
printf(" 6.患病时间\n ");
printf(" 7.患病程度\n ");
printf(" 8.电话号码\n");
printf(" 0.返回\n");
while(k!=0)
{
printf(" 请选择修改内容:");
scanf("%d",&k);
printf(" 输入修改后的内容:");
switch(k)
{
case 1:
scanf("%s",p->name);
break;
case 2:
scanf("%s",p->card);
break;
case 3:
scanf("%s",p->sex);
break;
case 4:
scanf("%s",p->place);
break;
case 5:
scanf("%d",&p->age);
break;
case 6:
scanf("%d.%d.%d",&p->time.year,&p->time.month,&p->time.day);
break;
case 7:
scanf("%s",p->degree);
break;
case 8:
scanf("%s",p->phone);
break;
case 0:
break;
default:
printf(" 输入错误,请重新输入。\n");
break;
}
}
}
else
printf(" 该姓名病患不存在\n");
return ;
}
void change_card_people(struct people* head)
{
PEOPLE *p=head;
if(head==NULL)
{
printf(" 未录入信息,按任意键返回\n");
getch();
return ;
}
char num[20];
printf(" 请输入要修改病患的身份证号:");
scanf("%s",num);
while(strcmp(p->card,num)!=0&& p!=NULL)
{
p=p->next;
}
if(p!=NULL)
{
int k=1;
printf(" 1.姓名\n");
printf(" 2.身份证号\n ");
printf(" 3.性别\n ");
printf(" 4.住址\n ");
printf(" 5.年龄\n ");
printf(" 6.患病时间\n ");
printf(" 7.患病程度\n ");
printf(" 8.电话号码\n");
printf(" 0.返回\n");
while(k!=0)
{
printf(" 请选择修改内容:");
scanf("%d",&k);
switch(k)
{
case 1:
scanf("%s",p->name);
break;
case 2:
scanf("%s",p->card);
break;
case 3:
scanf("%s",p->sex);
break;
case 4:
scanf("%s",p->place);
break;
case 5:
scanf("%d",&p->age);
break;
case 6:
scanf("%d.%d.%d",&p->time.year,&p->time.month,&p->time.day);
break;
case 7:
scanf("%s",p->degree);
break;
case 8:
scanf("%s",p->phone);
break;
case 0:
break;
default:
printf(" 输入错误,请重新输入。\n");
break;
}
}
}
else if(p==NULL)
printf(" 该身份证号病患不存在\n");
return ;
}
void change_people(PEOPLE* head)
{
int k;
printf(" *******************************\n");
printf(" ** 1. 姓名查询修改 **\n");
printf(" ** 2. 身份证号查询修改 **\n");
printf(" ** 0. 返回 **\n");
printf(" *******************************\n");
while(1)
{
printf(" 请选择查询方式 :");
scanf("%d",&k);
if(k==1)
{
change_name_people(head);
}
else if(k==2)
{
change_card_people(head);
}
else if(k==0)
break;
else
printf(" 输入错误,请重新输入。");
}
}
int encrypt_people(char code1[])
{
char code2[20]={'1','2','3','4','5','6'};
return strcmp(code1,code2);
}
//加密函数
PEOPLE * delete_name_people(PEOPLE *head)
{
PEOPLE *p1,*p2;
char sum[20];
printf(" 请输入删除的病患姓名:");
scanf("%s",sum);
p1=head;
while( strcmp(p1->name,sum) && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(strcmp(p1->name,sum)==0)
{
if(head==p1)
head=p1->next;
else
p2->next=p1->next;
printf(" 删除成功!!\n任意键继续");
getch();
return head;
}
else
printf(" 找不到姓名为%s的病患\n",sum);
return head;
}
PEOPLE * delete_card_people(PEOPLE *head)
{
PEOPLE *p1,*p2;
char sum[20];
printf(" 请输入删除的病患身份证号:");
scanf("%s",sum);
p1=head;
while( strcmp(p1->card,sum) && p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
if(strcmp(p1->card,sum)==0)
{
if(head==p1)
head=p1->next;
else
p2->next=p1->next;
printf(" \t删除成功!!任意键继续\n");
getch();
return head;
}
else
printf(" 找不到身份证号为%s的病患\n",sum);
return head;
}
PEOPLE * delete_people(PEOPLE *head)
{
int k;
printf(" *******************************\n");
printf(" ** 1. 姓名查询删除 **\n");
printf(" ** 2. 身份证号查询删除 **\n");
printf(" ** 0. 返回 **\n");
printf(" *******************************\n");
while(1)
{
printf(" 请选择删除方式 :");
scanf("%d",&k);
if(k==1)
{
head=delete_name_people(head);
}
else if(k==2)
{
head=delete_card_people(head);
}
else if(k==0)
break;
else
printf(" 输入错误,请重新输入。\n");
}
return head;
}
void insert_people(PEOPLE *head)
{
int i;
char named[20];
PEOPLE *p1,*p2,*p3;
p1=head;
p3=(PEOPLE *)malloc(sizeof(PEOPLE));
p3->next=NULL;
printf("\n\t\t\t☆☆☆插入数据☆☆☆\n");
printf("----------------------------------------------------------------------\n");
printf("请输入插入者的资料:\n");
printf(" 请录入病患信息\n");
printf(" 姓名:");
scanf("%s",p3->name);
printf(" 性别:");
scanf("%s",p3->sex);
printf(" 身份证号:");
scanf("%s",p3->card);
printf(" 年龄:");
scanf("%d",&p3->age);
printf(" 确诊日期:(注:输入格式 年.月.日)");
scanf("%d.%d.%d",&p3->time.year,&p3->time.month,&p3->time.day);
while(p3->time.month<=0||p3->time.month>12||p3->time.day<=0||p3->time.day>31)
{
printf("\n 输入有误,请重新输入:");
scanf("%d.%d.%d",&p3->time.year,&p3->time.month,&p3->time.day);
}
printf(" 患病情况:");
scanf("%s",p3->degree);
printf(" 住址:");
scanf("%s",&p3->place);
printf(" 电话号码:");
scanf("%s",p3->phone);
printf("\n插入选项\n");
printf("1.首位置插入\t2.尾位置插入\t3.前插\n");
printf("请输入你的选择:");
scanf("%d",&i);
switch(i)
{
case 1:
p3->next=p1;
head=p3;
break;
case 2:
while(p1->next!=NULL)
{
p2=p1;
p1=p1->next;
}
p1->next=p3;
break;
case 3:
printf("请输入姓名(前插):");
scanf("%s",named);
while(strcmp(named,p1->name)!=0)
{
p2=p1;
p1=p1->next;
}
p2->next=p3;
p3->next=p1;
break;
}
printf("插入成功!\n");
printf("======================================================================\n");
return;
}
void statistics_place_people(PEOPLE *head)
{
PEOPLE *p;
char sum[20];
int i=0;
p=head;
printf(" 请输入要统计的地址:");
scanf("%s",sum);
while(p!=NULL)
{
if(strcmp(p->place,sum)==0)
{
i++;
printf(" 姓名:%s\n",p->name);
printf(" 性别:%s\n",p->sex);
printf(" 年龄:%d\n",p->age);
printf(" 身份证号:%s\n",p->card);
printf(" 确诊日期:%d.%d.%d\n",p->time.year,p->time.month,p->time.day);
printf(" 患病情况:%s",p->degree);
printf(" 住址:%s\n",p->place);
printf(" 电话号码:%s\n0",p->phone);
}
p=p->next;
}
printf(" 共计%s的病患%d人\n",sum,i);
printf(" 按任意键返回。\n");
getch();
return ;
}
//统计功能
void statistics_age_people(PEOPLE *head)
{
PEOPLE *p;
int sum;
int i=0;
p=head;
printf(" 请输入要统计的年龄:");
scanf("%d",&sum);
while(p!=NULL)
{
if(p->age==sum)
{
i++;
printf(" 姓名:%s\n",p->name);
printf(" 性别:%s\n",p->sex);
printf(" 年龄:%d\n",p->age);
printf(" 身份证号:%s\n",p->card);
printf(" 确诊日期:%d.%d.%d\n",p->time.year,p->time.month,p->time.day);
printf(" 患病情况:%s",p->degree);
printf(" 住址:%s\n",p->place);
printf(" 电话号码:%s\n0",p->phone);
}
p=p->next;
}
printf(" 共计%d岁的病患%d人\n",sum,i);
printf(" 按任意键返回。\n");
getch();
return ;
}
void statistics_degree_people(PEOPLE *head)
{
PEOPLE *p;
char sum[20];
int i=0;
p=head;
printf(" 请输入要统计的患病情况:");
scanf("%s",sum);
while(p!=NULL)
{
if(strcmp(p->degree,sum)==0)
{
i++;
printf(" 姓名:%s\n",p->name);
printf(" 性别:%s\n",p->sex);
printf(" 年龄:%d\n",p->age);
printf(" 身份证号:%s\n",p->card);
printf(" 确诊日期:%d.%d.%d\n",p->time.year,p->time.month,p->time.day);
printf(" 患病情况:%s",p->degree);
printf(" 住址:%s\n",p->place);
}
p=p->next;
}
printf(" 共计%s级病患%d人\n",sum,i);
printf(" 按任意键返回。\n");
getch();
return ;
}
void statistics_sex_people(PEOPLE *head)
{
PEOPLE *p;
char sum[20];
int i=0;
p=head;
printf(" 请输入要统计的性别:");
scanf("%s",sum);
while(p!=NULL)
{
if(strcmp(p->sex,sum)==0)
{
i++;
printf(" 姓名:%s\n",p->name);
printf(" 性别:%s\n",p->sex);
printf(" 年龄:%d\n",p->age);
printf(" 身份证号:%s\n",p->card);
printf(" 确诊日期:%d.%d.%d\n",p->time.year,p->time.month,p->time.day);
printf(" 患病情况:%s",p->degree);
printf(" 住址:%s\n",p->place);
printf(" 电话号码:%s\n0",p->phone);
}
p=p->next;
}
printf(" 共计%s病患%d人\n",sum,i);
printf(" 按任意键返回。\n");
getch();
return ;
}
void statistics_age_sex_people(PEOPLE *head)
{
PEOPLE *p;
int sum;
char num[20];
int i=0;
p=head;
printf(" 请输入要统计的年龄:");
scanf("%d",&sum);
printf(" 请输入要统计的性别:");
scanf("%s",num);
while(p!=NULL)
{
if(p->age==sum&&strcmp(p->sex,num)==0)
{
i++;
printf(" 姓名:%s\n",p->name);
printf(" 性别:%s\n",p->sex);
printf(" 年龄:%d\n",p->age);
printf(" 身份证号:%s\n",p->card);
printf(" 确诊日期:%d.%d.%d\n",p->time.year,p->time.month,p->time.day);
printf(" 患病情况:%s",p->degree);
printf(" 住址:%s\n",p->place);
printf(" 电话号码:%s\n0",p->phone);
}
p=p->next;
}
printf(" 共计%d岁的%s病患%d人\n",sum,num,i);
printf(" 按任意键返回。\n");
getch();
return ;
}
void statistics_place_degree_people(PEOPLE *head)
{
PEOPLE *p;
char num[20],sum[20];
int i=0;
p=head;
printf(" 请输入要统计的位置:");
scanf("%d",&sum);
printf(" 请输入要统计的病情:");
scanf("%s",num);
while(p!=NULL)
{
if(strcmp(p->place,sum)==0&&strcmp(p->sex,num)==0)
{
i++;
printf(" 姓名:%s\n",p->name);
printf(" 性别:%s\n",p->sex);
printf(" 年龄:%d\n",p->age);
printf(" 身份证号:%s\n",p->card);
printf(" 确诊日期:%d.%d.%d\n",p->time.year,p->time.month,p->time.day);
printf(" 患病情况:%s",p->degree);
printf(" 住址:%s\n",p->place);
printf(" 电话号码:%s\n0",p->phone);
}
p=p->next;
}
printf(" 共计%s岁的%s病患%d人\n",sum,num,i);
printf(" 按任意键返回。\n");
getch();
return ;
}
void statistics_people(PEOPLE *head)
{
int k;
printf(" *******************************\n");
printf(" ** 1. 住址统计 **\n");
printf(" ** 2. 年龄统计 **\n");
printf(" ** 3. 性别统计 **\n");
printf(" ** 4. 病情统计 **\n");
printf(" ** 5. 年龄—性别统计 **\n");
printf(" ** 6. 住址—病情统计 **\n");
printf(" ** 0. 返回 **\n");
printf(" *******************************\n");
while(1)
{
printf(" 请选择统计方式 :");
scanf("%d",&k);
if(k==1)
{
statistics_place_people(head);
}
else if(k==2)
{
statistics_age_people(head);
}
else if(k==3)
{
statistics_sex_people(head);
}
else if(k==4)
{
statistics_degree_people(head);
}
else if(k==5)
{
statistics_age_sex_people(head);
}
else if(k==6)
{
statistics_place_degree_people(head);
}
else if(k==0)
break;
else
printf(" 输入错误,请重新输入。\n");
}
}
PEOPLE *sort_age_add_people(PEOPLE *head)
{
PEOPLE *h,*p,*q1,*q2;
if(head==NULL)
{
printf(" 目前尚未录入数据!按任意键返回.");
getch();
return (head);
}
h = NULL;
p=head;
while(p!=NULL)
{
head=head->next;
q1=q2=h;
while(q2!=NULL)
{
if(p->age<q2->age)
break;
q1=q2;
q2=q2->next;
}
if(q1==q2)
{
p->next = q1;
h = p;
}
else
{
p->next = q2;
q1->next = p;
}
p=head;
}
printf(" 排序结束!按任意键返回.\n");
getch();
return (h);
}
PEOPLE *sort_age_less_people(PEOPLE *head)
{
PEOPLE *h,*p,*q1,*q2;
if(head==NULL)
{
printf(" 目前尚未录入数据!按任意键返回.");
getch();
return (head);
}
h = NULL;
p=head;
while(p!=NULL)
{
head=head->next;
q1=q2=h;
while(q2!=NULL)
{
if(p->age>q2->age)
break;
q1=q2;
q2=q2->next;
}
if(q1==q2)
{
p->next = q1;
h = p;
}
else
{
p->next = q2;
q1->next = p;
}
p=head;
}
printf(" 排序结束!按任意键返回.\n");
getch();
return (h);
}
PEOPLE *sort_degree_add_people(PEOPLE *head)
{
PEOPLE *h,*p,*q1,*q2;
if(head==NULL)
{
printf(" 目前尚未录入数据!按任意键返回.");
getch();
return (head);
}
h = NULL;
p=head;
while(p!=NULL)
{
head=head->next;
q1=q2=h;
while(q2!=NULL)
{
if(strcmp(p->degree,q2->degree)<0)
break;
q1=q2;
q2=q2->next;
}
if(q1==q2)
{
p->next = q1;
h = p;
}
else
{
p->next = q2;
q1->next = p;
}
p=head;
}
printf(" 排序结束!按任意键返回.\n");
getch();
return (h);
}
PEOPLE *sort_degree_less_people(PEOPLE *head)
{
PEOPLE *h,*p,*q1,*q2;
if(head==NULL)
{
printf(" 目前尚未录入数据!按任意键返回.");
getch();
return (head);
}
h = NULL;
p=head;
while(p!=NULL)
{
head=head->next;
q1=q2=h;
while(q2!=NULL)
{
if(strcmp(p->degree,q2->degree)>0)
break;
q1=q2;
q2=q2->next;
}
if(q1==q2)
{
p->next = q1;
h = p;
}
else
{
p->next = q2;
q1->next = p;
}
p=head;
}
printf(" 排序结束!按任意键返回.\n");
getch();
return (h);
}
PEOPLE *sort_people(PEOPLE *head)
{
int k=1;
printf(" *******************************\n");
printf(" ** 1. 年龄排序 **\n");
printf(" ** 2. 病情排序 **\n");
printf(" ** 0. 返回 **\n");
printf(" *******************************\n");
while(1)
{
printf(" 请选择排序方式 :");
scanf("%d",&k);
if(k==1)
{
system("cls");
int j;
printf(" *******************************\n");
printf(" ** 1. 升序排序 **\n");
printf(" ** 2. 降序排序 **\n");
printf(" ** 3. 0返回 **\n");
printf(" *******************************\n");
printf(" 请选择输入:");
while(1)
{
scanf("%d",&j);
if(j==1)
{
head=sort_age_add_people(head);
}
else if(j==2)
{
head=sort_age_less_people(head);
}
else if(j==0)
break;
else
printf("输入错误.\n");
}
}
else if(k==2)
{
system("cls");
int j=0;
printf(" *******************************\n");
printf(" ** 1. 升序排序 **\n");
printf(" ** 2. 降序排序 **\n");
printf(" ** 3. 0返回 **\n");
printf(" *******************************\n");
printf(" 请选择输入:");
while(1)
{
scanf("%d",&j);
if(j==1)
{
head=sort_age_add_people(head);
}
else if(j==2)
{
head=sort_age_less_people(head);
}
else if(j==0)
break;
else
printf("输入错误.\n");
}
}
else if(k==0)
break;
else
printf(" 输入错误,请重新输入。\n");
}
return head;
}
//用户注册系统
void regist()
{
//清屏
system("pause");
system("cls");
printf("\n\n\t\t\t欢迎使用新冠病患信息管理系统\n\n");
while(1)
{
//输入用户名
printf("\t\t请输入用户名[不能大于10个字符]:");
scanf("%s",reg_name);
//判断用户名
if(strlen(reg_name)<=10)
{
while(1)
{
//输入密码
printf("\n\t\t请输入密码[密码长度为八位]:");
scanf("%s",reg_pwd);
//判断密码
if(strlen(reg_pwd)==8)
{
printf("\n\n\t\t注册成功,您的用户名是%s,密码是%s\n\n",reg_name,reg_pwd);
break;
}
else
{
printf("\n\t\t密码的长度为%d,请重新输入\n",strlen(reg_pwd));
}
}
break;
}
else
{
printf("\n\t\t用户名的长度为%d,请重新输入\n\n",strlen(reg_name));
}
}
}
//判断是否注册
int judge()
{
if(strcmp(reg_name,"")==0&&strcmp(reg_pwd,"")==0)
{
printf("\n\n\t\t您尚未注册,请先注册!\n\n");
return 0;
}
else
{
return 1;
}
}
//用户登录
int dl()
{
int i;
system("pause");
system("cls");
printf("\n\n\t\t\t欢迎使用新冠病患信息管理系统\n\n");
//三次登录验证
for(i=1;i<=3;i++)
{
printf("\t\t请输入用户名:");
scanf("%s",on_name);
printf("\n\t\t请输入密 码:");
scanf("%s",on_pwd);
if(strcmp(reg_name,on_name)==0&&strcmp(reg_pwd,on_pwd)==0)
{
printf("\n\n\t\t登录成功,欢迎使用新冠病患信息管理系统\n\n");
return 0;
break;
}
else
{
return 1;
printf("\n\n\t\t登录失败,请重新登录,您还有%d次机会\n\n",3-i);
}
}
}
web安全
XSS可能发生的场景
3.输入的数据在事件中输出
与属性内输入相同
<img src="xx.jpg" onerror="${input}">
---------------->
<img src="xx.jpg" onerror=""><script>alert(/xss/)</script>">
<img src="xx.jpg" onerror="" onclick="alert(/xss/)">
4.在CSS中输出
css中输出同样存在xss风险
<style type="text/css">
body {background-img:url("${input}");}
</style>
---------------->
body {background-img:url("javascript:alert('xss')");}
5.在script标签内输出
<script>
var usrname = "${input}"
</script>
---------------->
var usrname = "1";alert(/xss/);//"此处的//为javascropt简称js的注释标记
XSS的修复
XSS的形成,是因为未对输入和输出进行严格的过滤,导致在页面执行JavaScript等客户端脚本。
1.在HTML中对特殊字符<>/’"&等符号进行字符转义
2.打开cookie中HttpOnly属性
此对防御xss不起作用,主要防止xss漏洞后续的cookie劫持攻击。xss的攻击手段太多,能够模拟正常操作,盗取信息,钓鱼等等,仅靠httponly不够。
来源:CSDN
作者:hcd20190721
链接:https://blog.csdn.net/hcd20190721/article/details/104730203