⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 train_booking_attach.c

📁 火车定标系统...用VC编译通过的
💻 C
📖 第 1 页 / 共 2 页
字号:
//	train_booking_attach.c -- 包含辅助函数
//
/////////////////////////////////////////////////////////////////////////////

#ifndef TRAIN_BOOKING_ATTACH_C_
#define TRAIN_BOOKING_ATTACH_C_

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <time.h>
#include <windows.h>

#include "train_booking_declare.h"
#include "train_booking_const.h"
#include "train_booking_unit.h"

/////////////////////////////////////////////////////////////////////////////



/////////////////////////////////////////////////////////////////////////////
// 函数功能:	释放车次链表及相关内存区域(列车标识、列车、车站链表)
//
// 函数参数:	train_sq_info_head:车次链表头结点指针
//
/////////////////////////////////////////////////////////////////////////////
status free_train_sq_info_list(train_sq_info *train_sq_info_head)
{
	train_sq_info *train_sq_info_pt;

	while (train_sq_info_head->next)	// 如果还有下一个结点没释放
	{
		train_sq_info_head = train_sq_info_head->next;
							// 指针指向下一个结点,第一次运行时跳过头结点
		train_sq_info_pt = train_sq_info_head;			// 取得要销毁的内存指针

		// 释放该车次的所有列车标识信息
		free_train_item_info_list(&train_sq_info_pt->train_item_list);

		// 释放该车次的所有列车信息
		free_train_info_list(&train_sq_info_pt->train_list);

		free(train_sq_info_pt);			// 释放内存
	}

	return OK;
}



/////////////////////////////////////////////////////////////////////////////
// 函数功能:	释放列车链表
//
// 函数参数:	train_info_head:列车链表头结点指针
//
/////////////////////////////////////////////////////////////////////////////
status free_train_info_list(train_info *train_info_head)
{
	train_info *train_info_pt;

	while (train_info_head->next)		// 如果还有下一个结点没释放
	{
		train_info_head = train_info_head->next;
							// 指针指向下一个结点,第一次运行时跳过头结点
		train_info_pt = train_info_head->next;		// 取得要释放内存指针

		// 释放该列车的站点信息内存
		free_station_info_list(&train_info_pt->station_links);
							
		free(train_info_pt);			// 释放列车内存
	}

	return OK;
}




/////////////////////////////////////////////////////////////////////////////
// 函数功能:	释放车站链表
//
// 函数参数:	station_info_head:车站链表头结点指针
//
/////////////////////////////////////////////////////////////////////////////
status free_station_info_list(station_info *station_info_head)
{
	station_info *station_info_pt;

	while (station_info_head->next)		// 如果还有下一个结点没释放
	{
		station_info_head = station_info_head->next;
							// 指针指向下一个结点,第一次运行时跳过头结点
		station_info_pt = station_info_head;		// 取得要销毁的内存指针
		free(station_info_pt);			// 释放车站内存
	}

	return OK;
}

/////////////////////////////////////////////////////////////////////////////
// 函数功能:	释放列车标识链表
//
// 函数参数:	train_item_head:列车标识链表头结点指针
//
/////////////////////////////////////////////////////////////////////////////
status free_train_item_info_list(train_item *train_item_head)
{
	train_item *train_item_pt;

	while (train_item_head->next)		// 如果还有下一个结点没释放
	{
		train_item_head = train_item_head->next;
								// 指针指向下一个结点,第一次运行时跳过头结点
		train_item_pt = train_item_head;			// 取得要销毁的内存指针
		free(train_item_pt);			// 释放列车标识内存
	}

	return OK;
}



/////////////////////////////////////////////////////////////////////////////
// 函数功能:	释放用户信息链表
//
// 函数参数:	passenger_info_head:用户信息链表头结点指针
//
/////////////////////////////////////////////////////////////////////////////
status free_passenger_info_list(passenger_info *passenger_info_head)
{
	passenger_info *passenger_info_pt;

	while (passenger_info_head->next)	// 如果还有下一个结点没释放
	{
		passenger_info_head = passenger_info_head->next;
							// 指针指向下一个结点,第一次运行时跳过头结点
		passenger_info_pt = passenger_info_head;	// 取得要销毁的内存指针

		// 释放系统消息链占用内存
		free_msgbox_item_list(&passenger_info_pt->sysmsg_links);

		// 释放订票信息链占用内存
		free_booked_list(&passenger_info_pt->booked_links);

		free(passenger_info_pt);		// 释放用户信息占用内存
	}

	return OK;
}



/////////////////////////////////////////////////////////////////////////////
// 函数功能:	释放用户系统消息链表
//
// 函数参数:	msg_box_item_head:用户系统消息链表头结点指针
//
/////////////////////////////////////////////////////////////////////////////
status free_msgbox_item_list(msgbox_item *msg_box_item_head)
{
	msgbox_item *msg_box_item_pt;

	while (msg_box_item_head->next)			// 如果还有下一个结点没释放
	{
		msg_box_item_head = msg_box_item_head->next;
							// 指针指向下一个结点,第一次运行时跳过头结点
		msg_box_item_pt = msg_box_item_head;	// 取得要销毁的内存指针

		free(msg_box_item_pt);		// 释放内存
	}

	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	释放用户已订票信息链表
//
// 函数参数:	booked_info_head:用户已订票信息链表头结点指针
//
/////////////////////////////////////////////////////////////////////////////
status free_booked_list(booked_info *booked_info_head)
{
	booked_info *booked_info_pt;

	while (booked_info_head->next)			// 如果还有下一个结点没释放
	{
		booked_info_head = booked_info_head->next;
							// 指针指向下一个结点,第一次运行时跳过头结点
		booked_info_pt = booked_info_head;	// 取得要销毁的内存指针

		free(booked_info_pt);		// 释放内存
	}

	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	释放用户标识链表
//
// 函数参数:	user_item_head:用户标识链表头结点指针
//
/////////////////////////////////////////////////////////////////////////////
status free_user_item_info_list(user_item *user_item_head)
{
	user_item *user_item_pt;

	while (user_item_head->next)		// 如果还有下一个结点没释放
	{
		user_item_head = user_item_head->next;
								// 指针指向下一个结点,第一次运行时跳过头结点
		user_item_pt = user_item_head;			// 取得要销毁的内存指针
		free(user_item_pt);				// 释放列车标识内存
	}

	return OK;
}



/////////////////////////////////////////////////////////////////////////////
// 函数功能:	延迟时间,单位为秒
//
// 函数参数:	sec:延迟秒数
//
/////////////////////////////////////////////////////////////////////////////
status delay(int sec)
{
	clock_t delay = sec * CLOCKS_PER_SEC;	// 换算延迟时间	
	clock_t start = clock();				// 取得当前时间

	while (clock() - start < delay);		// 计算时差是否满足条件

	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	字符菜单显示,序号为数组下标法
//
// 函数参数:	itme:菜单条目字符串数组
//				warn:附加提示信息(可选)
//				start:从第几项开始显示
//				end:显示到第几项
//
/////////////////////////////////////////////////////////////////////////////
key text_menu(char item[][MAX_MENU_LEN], char *warn, int start, int end)
{
	int i, t;
	char choice;

	do {
		CLS;

		if (*warn)			// 如果有附加信息串则输出
		{
			puts(warn);
		}

		printf("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
		for (i = start; i <= end; i++)
		{
			t = i + 1;
			if (10 == t)
			{
				t = 0;
			}
			printf("【%d】%s	\n", t, item[i]);
		}
		printf("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");

		printf("【提示】请作出一个选择:");
		choice = getch();
		putchar('\n');

		choice -= '1';			// 转换为便于判断的整数类型
	} while ((choice < start) || (choice > end));

	return choice + '1';		// 仍然返回字符
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	获取字符选择
//
// 函数参数:	case:可选项的字符组合(字符串)
//
/////////////////////////////////////////////////////////////////////////////
key get_choice(char *cases)
{
	char choice;
	int i, len = strlen(cases);
	
input:
	{
		printf("\n【提示】请作出一个选择:");
		choice = getch();
		
		for (i = 0; i < len; i++)	// 检测作出的选择是否在可选范围内
		{
			if (choice == cases[i])
			{
				return choice;		// 是则返回该选择
			}
		}
		goto input;
	}
	
	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	屏幕消息函数
//
// 函数参数:	head:消息类型:ERROR(错误);WARN(警告);INFO(信息);
//								TIP(提示)
//				body:消息正文
//				deal:消息发送完后处理方式:WC(等待确认并清屏);
//								W(等待确认);C(清屏);NULL(不做任何动作)
//
/////////////////////////////////////////////////////////////////////////////
status message(char *head, char *body, char *deal)
{
	char msg[MAX_MSG_LEN];

	// 生成消息串
	strcpy(msg, "");
	strcat(msg, head);
	strcat(msg, body);

	printf("%s\n", msg);

	if (deal == NULL)
	{
		return OK;		// 如果没有操作直接返回
	}
	
	// 根据参数执行后续操作
	if (!strcmp(WC, deal))
	{
		WAIT;
		CLS;
	}
	else if (!strcmp(W, deal))
	{
		WAIT;
	}
	else if (!strcmp(C, deal))
	{
		CLS;
	}
	
	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	一级路径文件名生成函数
//
// 函数参数:	dir_i:第一级目录名
//				filename:要操作的文件名
//
/////////////////////////////////////////////////////////////////////////////
status create_i_dir(char *finalpath, char *dir_i, char *filename)
{
	strcpy(finalpath, "");
	strcat(finalpath, dir_i);
	strcat(finalpath, "\\");
	strcat(finalpath, filename);

	return OK;
}


/////////////////////////////////////////////////////////////////////////////
// 函数功能:	二级路径文件名生成函数
//	
// 函数参数:	dir_i:第一级目录名
//				dir_ii:第二级目录名
//				filename:要操作的文件名
//
/////////////////////////////////////////////////////////////////////////////
status create_ii_dir(char *finalpath, char *dir_i, char *dir_ii, char *filename)
{
	strcpy(finalpath, "");
	strcat(finalpath, dir_i);
	strcat(finalpath, "\\");
	strcat(finalpath, dir_ii);
	strcat(finalpath, "\\");
	strcat(finalpath, filename);

	return OK;
}

/////////////////////////////////////////////////////////////////////////////
// 函数功能:	三级路径文件名生成函数
//
// 函数参数:	dir_i:第一级目录名
//				dir_ii:第二级目录名
//				dir_iii:第三级目录名
//				filename:要操作的文件名
//
/////////////////////////////////////////////////////////////////////////////
status create_iii_dir(char *finalpath, char *dir_i, char *dir_ii, 
					 char *dir_iii, char *filename)
{
	strcpy(finalpath, "");
	strcat(finalpath, dir_i);
	strcat(finalpath, "\\");
	strcat(finalpath, dir_ii);
	strcat(finalpath, "\\");
	strcat(finalpath, dir_iii);
	strcat(finalpath, "\\");
	strcat(finalpath, filename);

	return OK;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -