简单日程管理系统,包含用户管理以及多线程定时提醒等功能

用户日程管理

工作大致流程图

y=>新用户
y=>新用户
一直循环
命令行启动用户管理
是否新用户?(y/n)
输入用户名
检查用户名是否与已有用户名重复
重复
提示该用户名已被使用
再次输入
没有重复
输入密码
是否存在已有用户名与输入用户名重复,检查是否输入正确
不存在
用户名错误
再次输入
用户名正确
输入密码
检查用户对应密码是否正确?
不正确
密码正确
日程管理
创建子线程提醒
主线程
菜单选项(1.新增,2.查找,3.修改,4.删除,5.退出)
1.新增
提示当前日期,并提示输入日期
检查当前日期是否符合日期标准,是否在当前时间之后,是否与已有的事件冲突
输入事件
输入优先级
2.查找
列出查找子菜单
1.遍历 2.时间查找 3.事件查找
输出所有事件
输出指定时间事件
输出指定事件
3.修改
修改事件
1.通过事件内容修改时间
4.删除
列出删除子菜单
1.时间删除 2.事件内容删除 3.ID删除
输入时间,提示找到该时间所有事件,然后删除
输入内容,提示找到该内容所有事件,然后删除
找到ID,删除事件
5.退出
主线程退出,保留子线程
子线程
进入alert提醒函数
计算当前时间和任务时间与2020-1-1 00:00:00,的间隔秒数进行比较,判断是否提醒

源文件

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
#include <unistd.h>
#define LENGTH 100

char filename[LENGTH];//用户登录后创建或者访问对应文件夹

typedef struct Schedule {
	int ID;
	int year;
	int month;
	int day;
	int hour;
	int minute;
	int second;
	char content[LENGTH];
	char priority[LENGTH];
	struct Schedule* next;
}Schedule;

typedef struct  User{
	char name[LENGTH];
	char password[LENGTH];
	char HASH_Password[LENGTH];//加密后的密码
	struct Schedule *Schedule;
	struct User *next;	
}User;

//初始化用户链表
User* Init(){
	User *eHead = (User*)malloc(sizeof(User));
	eHead->next=NULL;
	if(eHead!=NULL){
		return eHead;
	}
	else{
		printf("空间分配失败!");
		exit(1);
	}
}


//从文件读取保存的用户
int Load(User *head,int n){
	FILE *data;//要读取的文件指针
    int i=0;//结构体数组移动
	for (; head->next != NULL; head = head->next);
	User* test = (User*)malloc(sizeof(User));
    if((data=fopen("userInfo","r"))==NULL){
        printf("Can not open file\n");
        return 0;
    }
    while(i<=n){
        fscanf(data,"%s %s\n ",test->name,test->HASH_Password);
		head->next=test;
        i++;
    }
    fclose(data);
    return 0;

}


//判断新用户是否有重名
int check_New(User *eHead,char *name){
	int flag=1;
	eHead=eHead->next;
	while(eHead!=NULL){
		if(strcmp(eHead->name,name)==0){
			flag=0;
			break;
		}
		eHead=eHead->next;
	}
	return flag;
}

//判断老用户用户名是否正确
int check_name(User *eHead,char *name){
	int flag=0;
	eHead=eHead->next;
	while(eHead!=NULL){
		if(strcmp(eHead->name,name)==0){
			flag=1;
			break;
		}
		eHead=eHead->next;
	}
	return flag;
}

//判断老用户密码是否正确
int check_key(User *eHead,char *name,char *key,char *Hkey){
	int flag=0;
	eHead=eHead->next;
	while(eHead!=NULL){
		if(strcmp(eHead->name,name)==0){
			strcpy(Hkey,eHead->HASH_Password);
			//strcpy(key,test->password);
			int i=0,len=strlen(Hkey);
			while (i<len)
			{
				Hkey[i]=Hkey[i]-i-5;
				i++;
			}
			if (strcmp(key,Hkey)==0)
			{
				flag=1;
				break;
			}
		}
		eHead=eHead->next;
	}
	return flag;
}


//初始化日程链表
Schedule *init(){
	Schedule *head = (Schedule*)malloc(sizeof(Schedule));
	head->next=NULL;
	if(head!=NULL){
		return head;
	}
	else{
		printf("空间分配失败!");
		exit(1);
	}
}
 
//检查输入时间是否正确,是否与已经有的事件时间冲突
 int check_time(int year, int month, int day,int hour,int min,int sec,Schedule *head)
{
    int monthDays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    int judg = 0;

    time_t timep;
    time(&timep);

    struct tm *p;
    p = gmtime(&timep);

    // 判断如果是闰年,则修改二月的monthDays[1]值为29
    if ((year % 400 == 0) ||(year % 100 != 0 && year % 4 == 0))
	{
		monthDays[1] = 29;
	}

    if(year<1900 + p->tm_year||year < 0){
		printf(" Are you sure the entered year[%d] is correct?\n", year);
	}
	else if(year>=(1900 + p->tm_year+1)){
		judg=1;
	}
	else if(year>=1900 + p->tm_year){
		if(month<1 + p->tm_mon||month < 1 || month > 12) {
			printf("Are you sure the entered month[%d] is correct?\n", month);
		}
		else if(month>=(1 + p->tm_mon+1)){
			judg=1;
		}
		else if(month>=1 + p->tm_mon){
			if(day < p->tm_mday || day < 1 || day > monthDays[month - 1]){
				printf("Are you sure the entered day[%d] is correct?\n", day);
			}
			else if(day>=p->tm_mday+1){
				judg=1;
			}
			else if( monthDays[month - 1] >= day && day >= p->tm_mday){
				if(hour < p->tm_hour+8){
					printf("Are you sure the entered hour[%d] is correct?\n", hour);
				}
				else if(hour>= p->tm_hour+9){
					judg=1;
				}
				else if(24>=hour && hour>=(p->tm_hour+8)){
					if(min<p->tm_min||min>60){
						printf("Are you sure the entered min[%d] is correct?\n", min);
					}
					else if(min>p->tm_min+1){
						judg=1;
					}
					else if(p->tm_min<=min && min<=60){
						if (p->tm_sec>sec||sec>60){
							printf("Are you sure the entered sec[%d] is correct?\n", sec);
						}
						else{
							judg=1;
						}
					}
				}
			}
		}
	}
	//判断日期是否重复
	head=head->next;
	while(head!=NULL){
		if (head->year==year&&head->month==month&&head->day==day&&head->hour==hour&&head->minute==min)
		{
			printf("There is already a task at the current time!\n");
			judg=0;
			break;
		}
		else{
			judg=1;
		}		
		head=head->next;
	}
    return judg;
}
 

//从文件读取保存的事件
int load(Schedule *head,int n){
	FILE *data;//要读取的文件指针
    int i=0;//结构题数组移动
	for (; head->next != NULL; head = head->next);
	Schedule* test = (Schedule*)malloc(sizeof(Schedule));
    if((data=fopen(filename,"a+"))==NULL){
        printf("Can not open file\n");
        return 0;
    }
    while(i<=n){
        fscanf(data,"%d %d %d  %d %d %d  %s %s\n ",
		&test->year,&test->month, &test->day,&test->hour, &test->minute, &test->second,test->content,test->priority);
		head->next=test;
        i++;
    }
    fclose(data);
    return 0;

}

//输入新的事件 总是从尾端插入
void insert(Schedule* eHead,Schedule *head) {
	int x=0;
    time_t timep;
    time(&timep);
    struct tm *p;
    p = gmtime(&timep);

	for (; eHead->next != NULL; eHead = eHead->next);
	Schedule* test = (Schedule*)malloc(sizeof(Schedule));
	test->next = NULL;
	do{
		printf("请输入日期和时间:yyyy-mm-dd hh:mm:ss(例如:2022-7-7 00:00:00)\n");
		printf("当前时间是:");
		printf("%d-%02d-%02d %02d:%02d:%02d\n", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour+8, p->tm_min, p->tm_sec);
		scanf("%d %*c %d %*c %d %d %*c %d %*c %d", &test->year, &test->month, &test->day,&test->hour, &test->minute, &test->second);
		x=check_time(test->year,test->month, test->day,test->hour, test->minute, test->second,head);
	}while(x==0);
	if(x)
		printf("Correct!\n");
	char c_tmp;
	while ((c_tmp = getchar() != '\n') && c_tmp != EOF);

	printf("请输入事件内容(最长为50个字符):\n");
	scanf("%s", test->content);
	while ((c_tmp = getchar() != '\n') && c_tmp != EOF);

	printf("请输入事件优先级(高级、中级、低级):\n");
	scanf("%s", test->priority);
	while ((c_tmp = getchar() != '\n') && c_tmp != EOF);

	FILE *fp;
	fp=fopen(filename, "a+");    //打开文件,储存粗略信息,单纯存储记录
	fprintf(fp, " %04d %02d %02d  %02d %02d %02d  %s %s \n ",
	test->year,test->month, test->day,test->hour, test->minute, test->second,test->content,test->priority);
	fclose(fp);
	printf("事件已成功保存!\n");
	eHead->next = test;
}
 

//保存文件内容
void save(Schedule *head){
	FILE *fp;
	fp=fopen(filename, "w");  
	head=head->next;
	while(head!=NULL){
		fprintf(fp, " %04d %02d %02d  %02d %02d %02d  %s %s \n ",
	head->year,head->month, head->day,head->hour, head->minute, head->second,head->content,head->priority);
		head=head->next;
	}
	fclose(fp);
} 
 
//比较两事件的时间先后
int compare(Schedule *a,Schedule *b){
	//将Int格式化为str,直接比较字符串的大小
	char str_a[100]={0};
	sprintf(str_a,"%d04%02d%02d%02d%02d%02d",a->year,a->month,a->day,a->hour,a->minute,a->second);
	char str_b[100]={0};
	sprintf(str_b,"%d04%02d%02d%02d%02d%02d",b->year,b->month,b->day,b->hour,b->minute,b->second);
	int n=strcmp(str_a,str_b);
	if(n>0){
		return 1;
	}
	else{
		return 0;
	}
}
 
 
//排序
Schedule* sort(Schedule *L){
	Schedule *p, *q, *next;
	int temp;
	p = L->next;

	for( ; p != NULL; p = p->next )    /*每次循环都找出一个最小值,将最小值交换到第一位,然后将指针向后移动一位*/
	{
		next = p;
		for( q = p->next; q; q = q->next )    /*由前向后遍历,找出最小的节点*/
		{
			if( compare(next,q)==1 )
				next = q;
		}
		if( next != p )
		{
				temp = p->year;
				p->year = next->year;
				next->year = temp;
 
				temp = p->month;
				p->month = next->month;
				next->month = temp;
 
				temp = p->day;
				p->day = next->day;
				next->day = temp;
 
				temp = p->hour;
				p->hour = next->hour;
				next->hour = temp;
 
				temp = p->minute;
				p->minute = next->minute;
				next->minute = temp;
 
				temp = p->second;
				p->second = next->second;
				next->second = temp;
 
				char tem[LENGTH];
				memcpy(tem,p->content,100);
				memcpy(p->content,next->content,100);
				memcpy(next->content,tem,100);
		}
	}
	return L;
}
 
 //分配ID
void Assign_ID(Schedule *head){
	int temp=1;

	for (head = head->next; head != NULL; head = head->next) {
		head->ID=temp;
		temp++;
	}
}
 
//通过事件ID删除任务
void deleteByID(Schedule *head){
	Schedule *before,*cur;
	int temp;
	printf("请输入事件ID:\n");
    scanf("%d",&temp);
	for(before=head,cur=head->next;cur!=NULL;before=before->next,cur=cur->next){
		if(cur->ID==temp){
			before->next=cur->next;
			printf("删除成功\n");
			break;
		}
	}
	if(cur==NULL){
		printf("未找到该事件\n");
	}
}

//通过日期删除事件
void deleteByDate(Schedule *head){
	Schedule *before,*cur;
	int year;
	int month;
	int day;
	int hour;
	int minute;
	int second;
 
	printf("请输入日期:yyyy/mm/dd(例如:2018/01/09)\n");
	scanf("%d %*c %d %*c %d",&year,&month,&day);
	printf("请输入具体时间:hh:MM:ss(例如:23:01:00)\n");
	scanf("%d %*c %d %*c %d",&hour,&minute,&second);
	for(before=head,cur=head->next;cur!=NULL;cur=cur->next,before=before->next){
		if(cur->day==day && cur->hour==hour && cur->minute==minute && cur->month==month && cur->second==second && cur->year==year){
			before->next=cur->next;
			printf("删除成功\n");
			break;
		}
	}
	if(cur==NULL){
		printf("未找到该事件\n");
	}
 
}
 
 
//通过事件内容删除事件
void deleteByContent(Schedule *head){
	Schedule *before,*cur;
	char temp[LENGTH];
	printf("请输入事件内容:\n");
    scanf("%s",temp);
	for(before=head,cur=head->next;cur!=NULL;before=before->next,cur=cur->next){
		if(strcmp(temp,cur->content)==0){
			before->next=cur->next;
			printf("删除成功\n");
			break;
		}
	}
	if(cur==NULL){
		printf("未找到该事件\n");
	}
}
 
//打印事件具体时间
void printInfo(Schedule *Sch){
 
	printf("ID: %03d 日期: %04d/%02d/%02d 时间: %02d:%02d:%02d 事件:%s 优先级:%s\n",Sch->ID,Sch->year,Sch->month,Sch->day,Sch->hour,Sch->minute,Sch->second,Sch->content,Sch->priority);
}
 
//修改事件时间
void modifyDate(Schedule *head){
	char temp[LENGTH];
	printf("请输入您要查找事件内容:\n");
	scanf("%s",temp);
	printf("查找中...");
	for(head=head->next;head!=NULL;head=head->next){
		if(head==NULL){
			printf("未找到该事件\n");
			return;
		}
		if(strcmp(temp,head->content)==0){
			printf("已找到:\n");
			printInfo(head);
			int year;
			int month;
			int day;
			int hour;
			int minute;
			int second;
			printf("进行修改:");
			printf("请输入日期:yyyy/mm/dd(例如:2018/01/09)\n");
			scanf("%d %*c %d %*c %d",&year,&month,&day);
			printf("请输入具体时间:hh:MM:ss(例如:23:01:00)\n");
			scanf("%d %*c %d %*c %d",&hour,&minute,&second);
			head->year=year;
			head->month=month;
			head->day=day;
			head->hour=hour;
			head->minute=minute;
			head->second=second;
		}
	}
	printf("修改完成\n");
 
}
 
//遍历链表
void travel(Schedule *head){
	head=head->next;
	while(head!=NULL){
		printInfo(head);
		head=head->next;
	}
}
 
// 通过具体日期查找事件
void findByDate(Schedule *head){
	int year;
	int month;
	int day;
	int hour;
	int minute;
	int second;
	printf("请输入日期:yyyy/mm/dd(例如:2018/01/09)\n");
	scanf("%d %*c %d %*c %d",&year,&month,&day);
	printf("请输入具体时间:hh:MM:ss(例如:23:01:00)\n");
	scanf("%d %*c %d %*c %d",&hour,&minute,&second);
	printf("查找中...");
	for(head=head->next;head!=NULL;head=head->next){
		if(head->day==day && head->hour==hour && head->minute==minute && head->month==month && head->second==second && head->year==year){
			printf("已找到:\n");
			printInfo(head);
			break;
		}
	}
	if(head==NULL){
		printf("未找到该事件\n");
	}
}
 
 
//通过事件内容查找事件
void findByScheduleContent(Schedule *head){
	char temp[LENGTH];
	printf("请输入您要查找事件内容:\n");
	scanf("%s",temp);
	printf("查找中...");
	for(head=head->next;head!=NULL;head=head->next){
		if(strcmp(temp,head->content)==0){
			printf("已找到:\n");
			printInfo(head);
			break;
		}
	}
	if(head==NULL){
		printf("未找到该事件\n");
	}
}
 
 

//查找的子菜单,分为 1 遍历 2时间查找 3 事件查找
void find(Schedule *head){
	char decide = 'y';                          //定义while变量,函数是否继续进行
	int num;                                  //定义switch变量,函数跳转到哪个子函数
	while (decide != 'n')
	{
		printf("  ***************************************************\n");
		printf("  ****  1  遍历  2 时间查找   3 事件查找  4 退出 ****\n");
		printf("  ***************************************************\n");
		scanf("%d", &num);
		fflush(stdin);
		switch (num)
		{
		case 1:
			travel(head);
			break;
		case 2:
			findByDate(head);
			break;
		case 3:
			findByScheduleContent(head);
			break;
		default:
			decide = 'n';
			break;
		}
	}
}

 
//删除事件的子菜单,分为 1 时间查找删除 2事件查找删除 3 ID查找删除
void ScheduleDelete(Schedule *head){
	char decide = 'y';                          //定义while变量,函数是否继续进行
	int num;                                  //定义switch变量,函数跳转到哪个子函数
	while (decide != 'n')
	{
		printf("  ***************************************************\n");
		printf("  **** 	   1 时间删除   2 事件删除  3 ID删除  4 退出	 ****\n");
		printf("  ***************************************************\n");
		scanf("%d", &num);
		fflush(stdin);
		switch (num)
		{
		case 1:
			deleteByDate(head);
			break;
		case 2:
			deleteByContent(head);
			break;
		case 3:
			deleteByID(head);
			break;
		default:
			decide = 'n';
			break;
		}
	}
}
 
// 获得2022-1-1 00:00:00到当前时间(忽略秒,只计算到分)的秒数
long long int difpsec(){
	int monthDays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
	int judg = 0;
	time_t t;
	struct tm* llt;
	time(&t);//获取Unix时间戳。
	llt = localtime(&t);//转为时间结构。
	int flag = 0,sumday=0,year,md,difyear;
	int pyear = llt->tm_year + 1900 - 2022;
	int pmon = llt->tm_mon + 1-1;
	int pday = llt->tm_mday-1;
	int phour = llt->tm_hour;
	int pmin = llt->tm_min;
	for (difyear = 0; difyear <= pyear; difyear++) {
		if (difyear == 0) {//此时在计算当前年的天数
			// 判断如果是闰年,则修改二月的monthDays[1]值为29
			if (((llt->tm_year+1900) % 400 == 0) || ((llt->tm_year + 1900) % 100 != 0 && (llt->tm_year + 1900) % 4 == 0))
			{
				monthDays[1] = 29;
			}
			for (md = 0; md <= pmon; md++) {
				sumday = sumday + monthDays[md];
			}
			sumday = sumday + pday;
		}
		else if (difyear >= 1) {//此时在计算以前年的天数
			year = llt->tm_year + 1900 - difyear;
			// 判断如果是闰年,天数加366,否则加365
			if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0))
			{
				sumday = sumday + 366;
			}
			else {
				sumday = sumday + 365;
			}
		}
	}
	long long int sec = 0;
	sec = ((sumday * 24 + phour) * 60 + pmin) * 60+llt->tm_sec;
	return sec;
}


// 提醒有无即将需要完成的事件
void *alert(void *arg) {
	while(1){
		Schedule *Head;                                //定义链表的头指针
		Head = init();                              //给头指针开辟空间
		Head->next = NULL;                          //初始化头指针
		
		FILE *fp;
		int Flag = 0, count = 0;
		if((fp = fopen(filename, "a+")) == NULL){
			printf("Can not open file\n");
		}
		while(!feof(fp))
		{
			Flag = fgetc(fp);
			if(Flag == '\n'){
				count++;
			}
		}
		fclose(fp);
		for (int i = 0; i < count; i++)
		{
			load(Head,i);
		}
		Head=sort(Head);
		Assign_ID(Head);

		time_t t;
		struct tm* p;
		time(&t);//获取Unix时间戳。
		p = localtime(&t);//转为时间结构。

		int flag=0;
		long long int sec = 0,psec=0;
		int monthDays[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
		Head=Head->next;
		while(Head != NULL){
			int sumday=0,year=0,md=0,difyear=0;
			int pyear = Head->year - 2022;
			int pmon = Head->month -1;
			int pday = Head->day-1;
			int phour = Head->hour;
			int pmin = Head->minute;
			psec=difpsec();//当前时间距离2022-1-1 00:00:00的秒数
			for (difyear = 0; difyear <= pyear; difyear++) {
				if (difyear == 0) {//此时在计算链表储存年份的天数
					// 判断如果是闰年,则修改二月的monthDays[1]值为29
					if ((Head->year % 400 == 0) || (Head->year % 100 != 0 && Head->year % 4 == 0))
					{
						monthDays[1] = 29;
					}
					for (md = 0; md <= pmon; md++) {
						sumday = sumday + monthDays[md];
					}
					sumday = sumday + pday;
				}
				else if (difyear >= 1) {//此时在计算链表储存年份以前年的天数
					year = Head->year - difyear;
					// 判断如果是闰年,天数加366,否则加365
					if ((year % 400 == 0) || (year % 100 != 0 && year % 4 == 0))
					{
						sumday = sumday + 366;
					}
					else {
						sumday = sumday + 365;
					}
				}
			}
			sec = ((sumday * 24 + phour) * 60 + pmin) * 60+Head->second;//任务距离2022-1-1 00:00:00的秒数
			if (flag==0 && (sec-psec)<=1800 && (sec-psec)>=0) {
				printf("\n\n  ****************************************************\n");
				printf("*************    你有如下事件将要完成:     *************\n");
				printf("*****   日期: %04d/%02d/%02d 时间: %02d:%02d:%02d 事件:%s    *****\n ",Head->year, Head->month, Head->day, 
					Head->hour,Head->minute, Head->second, Head->content);
				printf("  ****************************************************\n");
				flag = 1;
			}
			while (flag==1 && difpsec()<=sec)
			{
				
			}
			Head = Head->next;
		}
		while (flag==0)
		{
			sleep(60);
			break;
		}
	}
}
 
 
 
//菜单列表
void menu(){
	pthread_t th2;

	char decide = 'y';                          //定义while变量,函数是否继续进行
	int num = 0;                                //定义switch变量,函数跳转到哪个子函数
	Schedule *head;                                //定义链表的头指针
	head = init();                              //给头指针开辟空间
	head->next = NULL;                          //初始化头指针
 	
	FILE *fp;
	int flag = 0, count = 0;
	if((fp = fopen(filename, "a+")) == NULL){
		printf("Can not open file\n");
	}
	while(!feof(fp))
	{
		flag = fgetc(fp);
		if(flag == '\n'){
			count++;
		}
	}
	fclose(fp);
	for (int i = 0; i < count; i++)
	{
		load(head,i);
	}
	head=sort(head);
	Assign_ID(head);

	pthread_create(&th2,NULL,alert,NULL);


	while (decide != 'n')
	{
	    printf("  ****************************************************\n");
        printf("  **********           日程管理系统           ********\n");
		printf("  ****************************************************\n");
		printf("  **********     1 输入  2 查找  3 修改       ********\n");
		printf("  **********         4 删除  5 退出           ********\n");
		printf("  ****************************************************\n");
		sleep(3);
		scanf("%d", &num);
		switch (num)
		{
		case 1:
			insert(head,head);
			head=sort(head);
			Assign_ID(head);
			break;
		case 2:
			find(head);
			break;
		case 3:
			modifyDate(head);
			save(head);
			break;
		case 4:
			ScheduleDelete(head);
			head=sort(head);
			Assign_ID(head);
			save(head);
			break;
		default:
			decide = 'n';
			break;
		}
	}
	pthread_detach(th2);
}
 
//输入新的用户 总是从尾端插入
void Insert(User* eHead,User *head) {
	for (; eHead->next != NULL; eHead = eHead->next);
	User* test = (User*)malloc(sizeof(User));
	test->next = NULL;
	int judg=0;
	char choice[1];
	extern char filename[LENGTH];
	printf("是新用户么?(输入Y/N,不区分大小写)\n");
	scanf("%s",choice);
	if (strcmp("Y",choice)==0||strcmp(choice,"y")==0)
	{
		while(judg==0){
			printf("请输入用户名:\n");
			scanf("%s",test->name);
			judg=check_New(head,test->name);
			if (judg==1)
			{
				strcpy(filename,test->name);
				break;
			}
			printf("当前用户名已被使用,请重新输入\n");
		}

		char c_tmp;
		while ((c_tmp = getchar() != '\n') && c_tmp != EOF);

		if(judg){
			printf("请输入密码:\n");
			char key[LENGTH]={'\0'};
			scanf("%s",key);
			printf("%s",key);
			strcpy(test->password,key);
			//strcpy(key,test->password);
			int i=0,len=strlen(key);
			while (i<len)
			{
				key[i]=key[i]+i+5;
				i++;
			}
			strcpy(test->HASH_Password,key);
		}
		FILE *fp;
		fp=fopen("userInfo", "a+");    //打开文件,储存粗略信息,单纯存储记录	
		fprintf(fp,"%s %s\n",test->name,test->HASH_Password);
		fclose(fp);
		printf("用户已成功注册!\n");
		menu();
	}
	else if(strcmp("N",choice)==0||strcmp(choice,"n")==0){
		printf("请输入用户名:\n");
		while(judg==0){
			scanf("%s",test->name);
			judg=check_name(head,test->name);
			if(judg==1){
				strcpy(filename,test->name);
				break;
			}
			printf("用户名不正确,请重新输入:\n");
		}
		
		judg=0;
		char c_tmp;
		while ((c_tmp = getchar() != '\n') && c_tmp != EOF);

		printf("请输入密码:\n");
		while(judg==0){
			char KEY[LENGTH];
			scanf("%s",KEY);
			judg=check_key(head,test->name,KEY,test->HASH_Password);
			printf("%d\n",judg);
			if(judg==1){
				break;
			}
			printf("用户密码不正确,请重新输入:\n");
		}
		if(judg==1){
			printf("用户成功登录!\n");
			menu();
		}
	}
	eHead->next = test;
}

int main()
{	

	time_t timep;
    time(&timep);
    struct tm *p;
    p = gmtime(&timep);

	printf("当前时间是:");
	printf("%d-%02d-%02d %02d:%02d:%02d\n", 1900 + p->tm_year, 1 + p->tm_mon, p->tm_mday, p->tm_hour+8, p->tm_min, p->tm_sec);
	//pthread_t th1;

	//pthread_create(&th1,NULL,main,NULL);

	char Decide = 'y';                          //定义while变量,函数是否继续进行
	User *eHead;                                //定义链表的头指针
	eHead = Init();                              //给头指针开辟空间
	eHead->next = NULL;                          //初始化头指针

	FILE *fp;
	int flag = 0, count = 0;
	if((fp = fopen("userInfo", "a+")) == NULL){
		printf("Can not open file\n");
	}
	while(!feof(fp))
	{
		flag = fgetc(fp);
		if(flag == '\n')
		count++;
	}
	fclose(fp);
	for (int i = 0; i < count; i++)
	{
		Load(eHead,i);
	}
	
	while (Decide != 'n'){
		printf("\n\n");
		printf("\t*******************************\n");
		printf("\t********* 用户登录     *********\n");
		printf("\t*******************************\n");
		printf("\n\n");
		Insert(eHead,eHead);
		return 0;
	}
}

Cmake文件

cmake_minimum_required(VERSION 3.10.2)

# set the project name
project(Schedule_Management)

set(CMAKE_BUILD_TYPE "Debug")

# add the executable
add_executable(Schedule_Management Schedule.cc)


set(CMAKE_CXX_FLAGS -lunistd)
set(CMAKE_CXX_FLAGS -pthread)
message(STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值