linux c写的一个航班查询的程序

华清远见毕业总结 人们都有一个现象,把不熟悉的问题向自己熟悉的领域上引,同时去学习比较难的知识和需要你长期去努力的事情,都不爱去做。喜欢看短时间就能够取得结果的事情。人性的弱点。所以你要保持不断学习的思想,充足的团队沟通能力。去不断的学习新的知识,让自己不断的去成长,最近从小朋友身上也学到了许多,对世界充满好奇和不断学习的能力。 阅读详情

之所以把这个代码称为一个程序而不叫一个项目,是因为鄙人还是个还没入行的新人,不敢妄自菲薄,只因一时兴起上来感慨吐槽一番,如果有什么不对的地方,请各位大牛高台贵手,如果能提点一番,小弟感激不尽大笑

废话不多,拿到题目就开干。

刚学完内核链表,就拿它来开刀。内核给你写好封装一些链表操作的接口函数,拿来用多爽,不用自己写大笑。这个写好的东西在哪呢,在内核目录的include/linux/下。

#include 
#include 
#include 
#include "kernel_list.h"

struct flight
{
	char flight_id[15];		//航班号					//航班号
	char flight_place[15];	//航班起飞站->终点站		//买票者的名字
	char flight_time[15];	//起飞时间					//买到的票的座位号
	int  flight_seat;		//航班总座位数				//票的张数
	float price;			//机票价格					//花费的金额
	int remain;				//剩余座位数
	char st[15];			//座位标志
	struct list_head mylist;
};
// 内核链表的初始化
struct flight * list_init()
{
	struct flight *head=malloc(sizeof(struct flight));
	INIT_LIST_HEAD(&(head->mylist));
	return head;
}
//判断链表是否为空
int kernellist_empty(struct flight *head)
{
	return list_empty(&(head->mylist));
}
// 创建新的节点
struct flight * new_node(char *flight_id,char *flight_place,char *flight_time,int  flight_seat,float price)
{
	struct flight *new=malloc(sizeof(struct flight));
	strcpy(new->flight_id,flight_id);
	strcpy(new->flight_place,flight_place);
	strcpy(new->flight_time,flight_time);
	new->flight_seat=flight_seat;
	new->remain=flight_seat;
	new->price=price;
	bzero(new->st,15);
	INIT_LIST_HEAD(&(new->mylist));
	return new;
}
// 添加新的节点到内核链表中 添加到head的前面
int kernellist_add(struct flight *new,struct flight *head)
{
	list_add_tail(&(new->mylist), &(head->mylist));
	return 0;
}
//添加到head的后面
int kernellist_add_tail(struct flight *new,struct flight *head)
{
	list_add(&(new->mylist), &(head->mylist));
	return 0;
}
//删除一个节点
int kernellist_del(struct flight *del)
{
	list_del(&(del->mylist));
	return 0;
}
// 打印航班信息
int show(struct flight *head)
{
	if(kernellist_empty(head))
	{
		printf("no any flight exist!\n");
		return 1;
	}
	printf("----------------------------------------------------------\n");	
	printf("flight_id	flight_place	flight_time	flight_seat  price\n");
	struct flight *pos;
	list_for_each_entry(pos,&(head->mylist),mylist) //该宏函数实际是个for循环
	//for (pos = list_entry((head)->next, typeof(*pos), member);  &pos->member != (head);  pos = list_entry(pos->member.next, typeof(*pos), member))
	{
		printf("%-16s%-16s%-16s%-13d%.2f\n",pos->flight_id,pos->flight_place,pos->flight_time,pos->flight_seat,pos->price);
	}
	printf("----------------------------------------------------------\n");	
	
	return 0;
}
//打印卖票信息
int show_ticket(struct flight *head)
{
	int i;
	if(kernellist_empty(head))
	{
		printf("no bodey buy ticket!\n");
		return 0;
	}
	printf("----------------------------------------------------------\n");	
	printf("flight_id	name		num		price   ticketnum\n");
	struct flight *pos;
	list_for_each_entry(pos,&(head->mylist),mylist) //该宏函数实际是个for循环
	//for (pos = list_entry((head)->next, typeof(*pos), member);  &pos->member != (head);  pos = list_entry(pos->member.next, typeof(*pos), member))
	{
		printf("%-16s%-16s%-16d%-8.2f",pos->flight_id,pos->flight_place,
										pos->flight_seat,pos->price);
		for(i=0;i<15;i++)
		{
			if(pos->flight_time[i] == 1)
				printf("%d ",i+1);
		}
		printf("\n");
	}
	printf("----------------------------------------------------------\n");	
	
	return 0;
}
//翻转航班信息
int reversal(struct flight *head)
{
	struct list_head *pos;
	pos = head->mylist.next;
	while(pos->next != &(head->mylist))
		list_move_tail(head->mylist.prev,pos);
	return 0;
}
//航班信息排序
int flight_sort(struct flight *head)
{
	int choose;
	struct list_head *posi;
	struct list_head *posj;
	struct list_head *temp;
	while(1)
	{
		printf(	"====================================================================\n"
				"[1]flight_id  [2]flight_time  [3]price  [4]reversal  [5]show [0]quit\n"					
				"====================================================================\n");
		if(scanf("%d",&choose) != 1 || getchar()!='\n')	//判断是否正确输入
		{
			choose=6;
			while(getchar() !=  '\n');
		}
		switch(choose)
		{
			case 0:
				return 0;		
				break;
			case 1:
				list_for_each(posi,&(head->mylist))
				//for (posi = head->mylist.next; posi != &(head->mylist);posi = posi->next)
				{
					for (posj = posi->next; posj != &(head->mylist);posj = posj->next)
					{
						if(strcmp(list_entry(posi,struct flight,mylist)->flight_id,list_entry(posj,struct flight,mylist)->flight_id)==1)
						{
							temp = posi->prev;
							list_move(posi,posj);
							list_move(posj,temp);
							
							temp=posi;
							posi = posj;
							posj = temp;	
						}		
					} 
				}
				break;
			case 2:
				list_for_each(posi,&(head->mylist))
				//for (posi = head->mylist.next; posi != &(head->mylist);posi = posi->next)
				{
					for (posj = posi->next; posj != &(head->mylist);posj = posj->next)
					{
						if(strcmp(list_entry(posi,struct flight,mylist)->flight_time,list_entry(posj,struct flight,mylist)->flight_time)==1)
						{
							temp = posi->prev;
							list_move(posi,posj);
							list_move(posj,temp);
							
							temp=posi;
							posi = posj;
							posj = temp;	
						}		
					} 
				}
				break;
			case 3:
				list_for_each(posi,&(head->mylist))
				//for (posi = head->mylist.next; posi != &(head->mylist);posi = posi->next)
				{
					for (posj = posi->next; posj != &(head->mylist);posj = posj->next)
					{
						if(list_entry(posi,struct flight,mylist)->price>list_entry(posj,struct flight,mylist)->price)
						{
							temp = posi->prev;
							list_move(posi,posj);
							list_move(posj,temp);
							
							temp=posi;
							posi = posj;
							posj = temp;	
						}		
					} 
				}
				break;
			case 4: 			
				reversal(head);
				show(head);
				break;
			case 5:
				show(head);
				break;
			default:
				printf("invalid input !!\n");		//输入错误
				break;
		}
	}
}
//买票
int flight_buy(struct flight *head,struct flight *masg)
{
	int i;
	int count = 0;
	char str[15];	//存放买票的航班号
	char name[15];	//存放买票的名字
	char seat[15];
	memset(seat,2,15);		//临时存放座位号  由于后面使用strcpy 所以不能用0
	struct flight *pos;
	int ticket;		//买票的张数
	struct flight *mynewnode;
	struct flight *n;
	
	show(head);
	while(1)
	{
		printf("enter flight id you want buy or quit to back primary menu\n");
		gets(str);
		if(strcmp(str, "quit") == 0)
			break;
		list_for_each_entry(pos,&(head->mylist),mylist)
		{
			if(strcmp(str,pos->flight_id) == 0)		//查找航班号
			{
				printf("enter how many you want buy\n");
				// scanf("%d",&ticket);
				// getchar();
lable1:			if(scanf("%d",&ticket) != 1 || getchar()!='\n')	//判断是否正确输入
				{
					while(getchar() !=  '\n');
					printf("invalid intput! try again\n");
					goto lable1;
				}
				if(ticket<=0)	//输入的票数小于等于0
				{
					printf("invalid intput! try again\n");
					goto lable1;
				}	
				printf("%s flight have %d tickets!\n",pos->flight_id,pos->remain);
				if(ticket > pos->remain)			//余票不足
				{
					printf("no have more tickets!\n");
				}
				else
				{
					printf("please enter you name!\n");
					gets(name);
					printf("you tiickets numbel is:\n");
					for(i=0;i<15;i++)			//分配座位号
					{
						if(pos->st[i] != 1)
						{
							pos->st[i]=1;
							count++;
							seat[i]=1;
							printf("%d\t",i+1);
						}
						if(count>=ticket)
						{
							count=0;
							break;
						}		
					}
					printf("\n");
					if(kernellist_empty(masg))	//买票链表为空
					{
						mynewnode = new_node(str,name,seat,ticket,ticket*pos->price);
						kernellist_add(mynewnode,masg);
					}
					else
					{
						list_for_each_entry(n,&(masg->mylist),mylist)	//查找是否有相同的票
						{
							if(strcmp(name,n->flight_place) == 0 && strcmp(str,n->flight_id) == 0)		//有相同的票则票数量添加
							{
								n->flight_seat+=ticket;
								n->price+=ticket*pos->price;
								for(i=0;i<15;i++)
								{
									if(seat[i] == 1)
										n->flight_time[i]=1;
								}
								break;
							}	
							if(n->mylist.next==&(masg->mylist))		//没有则建立一个新的结构体存放
							{
								mynewnode = new_node(str,name,seat,ticket,ticket*pos->price);
								kernellist_add(mynewnode,masg);
								break;
							}	
						}
					}
					
					printf("succeed buy tickets!\n");
					pos->remain -= ticket;		//余票减少
				}
				break;
			}
			if(pos->mylist.next==&(head->mylist))	//没有查找到航班号
				printf("no such flight exist!\n");
		}
		memset(seat,2,15);	//清空座位号
	}
}
//退票
int unticket(struct flight *p,struct flight *masg)
{
	int i;
	int ticketnum;		//退票数量
	int count=0;
	char str[15];		//名字
	char strid[15];		//航班号
	struct flight *pos;
	struct flight *pos1;
	while(1)
	{
		printf("please enter you name or quit to back!\n");
		gets(str);
		if(strcmp(str, "quit") == 0)
			break;
		printf("flight_id	name		num		price\n");
		list_for_each_entry(pos,&(masg->mylist),mylist)// 双向链表没有遍历完
		{
			if(strcmp(str,pos->flight_place) == 0)
			{
				printf("%-16s%-16s%-16d%.2f\n",pos->flight_id,pos->flight_place,pos->flight_seat,pos->price);
				// if(pos->flight_seat > 1)
				// {
					// pos->flight_seat -= 1;
				// }
				// else
					// kernellist_del(pos);
				// break;
				count++;
			}
			// if(pos->mylist.next==&(masg->mylist))
				// printf("no such ticket exist!\n");
		}
		if(count==0) //你没有买票
			printf("no such ticket exist!\n");
		else if(count > 1)	//你买了两种以上
		{
			printf("please enter you want flight id unticket!\n");
			gets(strid);
			list_for_each_entry(pos,&(masg->mylist),mylist)
			{
				if(strcmp(str,pos->flight_place) == 0 && strcmp(strid,pos->flight_id) == 0)
				{
					printf("you have ticket numbel is \n");
					// printf("flight_id	name		num		price\n");
					// printf("%-16s%-16s%-16d%.2f\n",pos->flight_id,pos->flight_place,pos->flight_seat,pos->price);
					for(i=0;i<15;i++)
					{
						if(pos->flight_time[i] == 1)
							printf("%d\t",i+1);
					}
					printf("\n");
					printf("how many you want unticket!\n");
lable:				if(scanf("%d",&ticketnum) != 1 || getchar()!='\n')	//判断是否正确输入
					{
						while(getchar() !=  '\n');
						printf("invalid intput! try again\n");
						goto lable;
					}
					if(pos->flight_seat < ticketnum || ticketnum <= 0)
					{
						printf("invalid intput! try again\n");
						goto lable;
					}
					else if(pos->flight_seat == ticketnum)	//全退
					{
						kernellist_del(pos);
						list_for_each_entry(pos1,&(p->mylist),mylist)
						{
							if(strcmp(strid, pos1->flight_id)==0)
							{
								pos1->remain += ticketnum;
								break;
							}	
						}
						printf("unticket successful!\n");
					}
					else 	// 退ticketnum张
					{
						pos->flight_seat -= ticketnum;		//你拥有的票减少ticketnum张
						list_for_each_entry(pos1,&(p->mylist),mylist)
						{
							if(strcmp(strid, pos1->flight_id)==0)
							{
								pos1->remain += ticketnum;		//剩余的票数增加
								break;
							}	
						}
						pos->price -= pos1->price*ticketnum; //你付的总价减少
						for(i=0;i<15;i++)
						{
							if(pos->flight_time[i] == 1) //座位号回收 默认从小开始回收
							{
								pos->flight_time[i]=2;
								ticketnum--;
							}
							if(ticketnum == 0)
								break;
						}
						printf("unticket successful!\n");						
					}
					break;
				}	
			}
		}
		else if(count==1)	//你只买了一种票
		{
			list_for_each_entry(pos,&(masg->mylist),mylist)
			{
				if(strcmp(str,pos->flight_place) == 0 )
				{
					printf("you have ticket numbel is \n");
					for(i=0;i<15;i++)
					{
						if(pos->flight_time[i]==1)
							printf("%d\t",i+1);
					}
					printf("\n");
					printf("how many you want unticket!\n");
lable2:				if(scanf("%d",&ticketnum) != 1 || getchar()!='\n')	//判断是否正确输入
					{
						while(getchar() !=  '\n');
						printf("invalid intput! try again\n");
						goto lable2;
					}
					if(pos->flight_seat < ticketnum || ticketnum <= 0)
					{
						printf("invalid intput! try again\n");
						goto lable2;
					}
					else if(pos->flight_seat == ticketnum)	//全退
					{
						kernellist_del(pos);
						list_for_each_entry(pos1,&(p->mylist),mylist)
						{
							if(strcmp(strid, pos1->flight_id)==0)
							{
								pos1->remain += ticketnum;
								break;
							}	
						}
						printf("unticket successful!\n");
					}
					else 
					{
						pos->flight_seat -= ticketnum;
						list_for_each_entry(pos1,&(p->mylist),mylist)
						{
							if(strcmp(strid, pos1->flight_id)==0)
							{
								pos1->remain += ticketnum;
								break;
							}	
						}
						pos->price -= pos1->price*ticketnum;
						for(i=0;i<15;i++)
						{
							if(pos->flight_time[i] == 1)
							{
								pos->flight_time[i]=2;
								ticketnum--;
							}
							if(ticketnum == 0)
								break;
						}
						printf("unticket successful!\n");						
					}
					break;
				}
			
			}
			
		}
		count = 0;
	}
	return 0;
}
//管理员执行函数
int admi(struct flight *p, char *password,struct flight *masg)
{
	int choose=0;
	char str1[15];
	char str2[15];
	char str3[15];
	int seat;
	float price;
	struct flight *mynewnode;
	struct flight *pos;
	struct flight *n;
	while(1)
	{
		printf("please enter password!\n");
		gets(str1);
		if(strcmp(str1,password) != 0)
		{
			printf("error password!\n");
			choose++;	
		}
		else 
			break;
		if(choose == 3)
		{
			return 1;
		}	
	}
			
	while(1)
	{
		printf(	"************************enter you choice**********************************\n"
				"[1]insert  [2]remove  [3]show  [4]clear  [5]sort [6]changepassword  [0]quit\n"					
				"**************************************************************************\n");
		if(scanf("%d",&choose) != 1 || getchar()!='\n')	//判断是否正确输入
		{
			choose=7;
			while(getchar() !=  '\n');
		}
		switch(choose)
		{
			case 0:
				return 0;
				break;
			case 1:
				while(1)
				{
					printf("enter flight id you want add or quit to back primary menu\n");
					gets(str1);
					if(strcmp(str1, "quit") == 0)
						break;
					printf("enter the flight place\n");
					gets(str2);
					printf("enter the flight time\n");
					gets(str3);
					if(str3[1]==':')		//判断时间输入格式,为后面的排序做准备
					{
						for(seat=4;seat>=0;seat--)
							str3[seat+1]=str3[seat];
						str3[0]=' '; 
					}
					printf("enter the flight seat\n");
					scanf("%d",&seat);
					getchar();
					printf("enter the flight price\n");
					scanf("%f",&price);
					getchar();
					mynewnode = new_node(str1,str2,str3,seat,price);
					printf("you want add the flight	who's id next\n");	//插入到哪个航班号的后面
					gets(str1);
					list_for_each_entry(pos,&(p->mylist),mylist)
					{
						if(strcmp(str1,pos->flight_id) == 0)
						{
							kernellist_add_tail(mynewnode,pos);
							break;
						}
						if(pos->mylist.next==&(p->mylist))		//如果没找到默认插到最后一个
						{
							printf("no such flight exist!\n");
							kernellist_add(mynewnode,p);
							break;
						}		
					}
				}
				show(p);
				break;
			case 2:
				while(1)
				{
					if(kernellist_empty(p))		//如果航班信息为空
					{
						printf("no any flight exist!\n");
						break;
					}
					printf("enter flight id you want remove or quit to back primary menu\n");
					gets(str1);
					if(strcmp(str1, "quit") == 0)
							break;
					list_for_each_entry(pos,&(p->mylist),mylist)// 双向链表没有遍历完
					{
						if(strcmp(str1,pos->flight_id) == 0)
						{
							kernellist_del(pos);
							break;
						}
						if(pos->mylist.next==&(p->mylist))
							printf("no such flight exist!\n");
					}	
					if(show(p))		//如果航班信息为空打印信息并退出
						break;
				}		
				break;
			case 3:
				while(1)
				{
					printf(	"---------------------------\n"
							"please enter you want print\n"
							"[1] print flight message\n"
							"[2] print ticket message\n"
							"[0] quit\n"
							"---------------------------\n");
					if(scanf("%d",&seat) != 1 || getchar()!='\n')	//判断是否正确输入
					{
						seat=3;
						while(getchar() !=  '\n');
					}
					if(seat == 1)
					{
						show(p);
					}	
					else if(seat == 2)
					{
						show_ticket(masg);
					}
					else if(seat == 0)
						break;
					else 
						printf("invalid input !!\n");
				}
				break;
			case 4:
				list_for_each_entry_safe(pos,n,&(p->mylist),mylist)  //安全删除条目
				{
					kernellist_del(pos);
					free(pos);
				}		
				break;
			case 5:
				flight_sort(p);
				break;
			case 6:
				printf("please enter new password!\n");
				gets(str1);
				printf("please enter new password again!\n");
				gets(str2);
				if(strcmp(str1,str2) != 0)
					printf(	"twice enter different!\n"
							"change fail!\n");
				else 
				{
					strcpy(password,str1);
					printf("change succeed!\n");
				}
				break;
			default:
				printf("invalid input !!\n");		//输入错误
				break;
		}
	}
	return 0;
}
//用户执行函数
int user(struct flight *p,struct flight *masg)
{
	int choose;
	while(1)
	{
		printf(	"************************enter you choice************************\n"
				"[1]buyticket  [2]unticket  [3]show  [4]sort [0]quit\n"					
				"****************************************************************\n");
		if(scanf("%d",&choose) != 1 || getchar()!='\n')	//判断是否正确输入
		{
			choose=5;
			while(getchar() !=  '\n');
		}
		switch(choose)
		{
			case 0:
				return 0;
				break;
			case 1:
				flight_buy(p,masg);
				break;
			case 2:
				unticket(p,masg);
				break;
			case 3:
				show(p);
				break;
			case 4:
				flight_sort(p);
				break;
			default:
				printf("invalid input !!\n");		//输入错误
				break;
		}
	}
	return 0;
}

int main(int argc,char *argv[])
{
	int choose;
	struct flight *p=list_init();
	struct flight *masg=list_init();
	char password[15] = "123";
	struct flight *mynewnode;
//	char st[15]={0};
	
	mynewnode = new_node("A001","gz->jy"," 8:30",6,260);
	kernellist_add(mynewnode,p);
	mynewnode = new_node("A002","gz->cs","10:30",8,160);
	kernellist_add(mynewnode,p);
	mynewnode = new_node("A003","gz->hz","12:30",6,185);
	kernellist_add(mynewnode,p);
	mynewnode = new_node("A004","gz->sz"," 9:50",4,230);
	kernellist_add(mynewnode,p);
	mynewnode = new_node("A005","gz->hn","22:30",12,175);
	kernellist_add(mynewnode,p);
	while(1)
	{
		printf("		Welcome to Flights System\n");
		printf(	"************************enter you choice************************\n"
				"[1]administrator  [2]user  [0]end\n"					
				"****************************************************************\n");
		//scanf("%d",&choose);
		if(scanf("%d",&choose) != 1 || getchar()!='\n')	//判断是否正确输入
		{
			choose=3;
			while(getchar() !=  '\n');
		}
			
		switch(choose)
		{
			case 0:
				return 0;			//程序结束
				break;
			case 1:
				admi(p, password,masg);
				break;
			case 2:
				user(p,masg);
				break;
			default:
				printf("invalid input !!\n");		//输入错误
				break;
		}
	}
	return 0;
}
#ifndef __DLIST_H
#define __DLIST_H

/* This file is from Linux Kernel (include/linux/list.h)
* and modified by simply removing hardware prefetching of list items.
* Here by copyright, credits attributed to wherever they belong.
* Kulesh Shanmugasundaram (kulesh [squiggly] isis.poly.edu)
*/

/*
* Simple doubly linked list implementation.
*
* Some of the internal functions (“__xxx”) are useful when
* manipulating whole lists rather than single entries, as
* sometimes we already know the next/prev entries and we can
* generate better code by using them directly rather than
* using the generic single-entry routines.
*/
/**
 * container_of - cast a member of a structure out to the containing structure
 *
 * @ptr:	the pointer to the member.
 * @type:	the type of the container struct this is embedded in.
 * @member:	the name of the member within the struct.
 *
 */
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

#define container_of(ptr, type, member) ({			\
        const typeof( ((type *)0)->member ) *__mptr = (ptr);	\
        (type *)( (char *)__mptr - offsetof(type,member) );})
/*
 * These are non-NULL pointers that will result in page faults
 * under normal circumstances, used to verify that nobody uses
 * non-initialized list entries.
 */
#define LIST_POISON1  ((void *) 0x00100100)
#define LIST_POISON2  ((void *) 0x00200)

struct list_head {
	struct list_head *next, *prev;
};

#define LIST_HEAD_INIT(name) { &(name), &(name) }

#define LIST_HEAD(name) \
struct list_head name = LIST_HEAD_INIT(name)

#define INIT_LIST_HEAD(ptr) do { \
	(ptr)->next = (ptr); (ptr)->prev = (ptr); \
} while (0)

/*
* Insert a new entry between two known consecutive entries.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static inline void __list_add(struct list_head *new,
				struct list_head *prev,
				struct list_head *next)
{
	next->prev = new;
	new->next = next;
	new->prev = prev;
	prev->next = new;
}

/**
* list_add – add a new entry
* @new: new entry to be added
* @head: list head to add it after
*
* Insert a new entry after the specified head.
* This is good for implementing stacks.
*/
static inline void list_add(struct list_head *new, struct list_head *head)
{
	__list_add(new, head, head->next);
}

/**
* list_add_tail – add a new entry
* @new: new entry to be added
* @head: list head to add it before
*
* Insert a new entry before the specified head.
* This is useful for implementing queues.
*/
static inline void list_add_tail(struct list_head *new, struct list_head *head)
{
	__list_add(new, head->prev, head);
}

/*
* Delete a list entry by making the prev/next entries
* point to each other.
*
* This is only for internal list manipulation where we know
* the prev/next entries already!
*/
static inline void __list_del(struct list_head *prev, struct list_head *next)
{
	next->prev = prev;
	prev->next = next;
}

/**
* list_del – deletes entry from list.
* @entry: the element to delete from the list.
* Note: list_empty on entry does not return true after this, the entry is in an undefined state.
*/
static inline void list_del(struct list_head *entry)
{
	__list_del(entry->prev, entry->next);
	entry->next = (void *) 0;
	entry->prev = (void *) 0;
}

/**
* list_del_init – deletes entry from list and reinitialize it.
* @entry: the element to delete from the list.
*/
static inline void list_del_init(struct list_head *entry)
{
	__list_del(entry->prev, entry->next);
	INIT_LIST_HEAD(entry);
}

/**
* list_move – delete from one list and add as another’s head
* @list: the entry to move
* @head: the head that will precede our entry
*/
static inline void list_move(struct list_head *list,
				struct list_head *head)
{
	__list_del(list->prev, list->next);
	list_add(list, head);
}

/**
* list_move_tail – delete from one list and add as another’s tail
* @list: the entry to move
* @head: the head that will follow our entry
*/
static inline void list_move_tail(struct list_head *list,
					struct list_head *head)
{
	__list_del(list->prev, list->next);
	list_add_tail(list, head);
}

/**
* list_empty – tests whether a list is empty
* @head: the list to test.
*/
static inline int list_empty(struct list_head *head)
{
	return head->next == head;
}

static inline void __list_splice(struct list_head *list,
					struct list_head *head)
{
	struct list_head *first = list->next;
	struct list_head *last = list->prev;
	struct list_head *at = head->next;

	first->prev = head;
	head->next = first;

	last->next = at;
	at->prev = last;
}

/**
* list_splice – join two lists
* @list: the new list to add.
* @head: the place to add it in the first list.
*/
static inline void list_splice(struct list_head *list, struct list_head *head)
{
if (!list_empty(list))
__list_splice(list, head);
}

/**
* list_splice_init – join two lists and reinitialise the emptied list.
* @list: the new list to add.
* @head: the place to add it in the first list.
*
* The list at @list is reinitialised
*/
static inline void list_splice_init(struct list_head *list,
struct list_head *head)
{
if (!list_empty(list)) {
__list_splice(list, head);
INIT_LIST_HEAD(list);
}
}

/**
* list_entry – get the struct for this entry
* @ptr:    the &struct list_head pointer.
* @type:    the type of the struct this is embedded in.
* @member:    the name of the list_struct within the struct.
*/
#define list_entry(ptr, type, member) \
((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))

/**
* list_for_each    -    iterate over a list
* @pos:    the &struct list_head to use as a loop counter.
* @head:    the head for your list.
*/
#define list_for_each(pos, head) \
for (pos = (head)->next; pos != (head); \
pos = pos->next)
/**
* list_for_each_prev    -    iterate over a list backwards
* @pos:    the &struct list_head to use as a loop counter.
* @head:    the head for your list.
*/
#define list_for_each_prev(pos, head) \
for (pos = (head)->prev; pos != (head); \
pos = pos->prev)

/**
* list_for_each_safe    -    iterate over a list safe against removal of list entry
* @pos:    the &struct list_head to use as a loop counter.
* @n:        another &struct list_head to use as temporary storage
* @head:    the head for your list.
*/
#define list_for_each_safe(pos, n, head) \
for (pos = (head)->next, n = pos->next; pos != (head); \
pos = n, n = pos->next)

/**
* list_for_each_entry    -    iterate over list of given type
* @pos:    the type * to use as a loop counter.
* @head:    the head for your list.
* @member:    the name of the list_struct within the struct.
*/
#define list_for_each_entry(pos, head, member)                \
for (pos = list_entry((head)->next, typeof(*pos), member);    \
&pos->member != (head);                     \
pos = list_entry(pos->member.next, typeof(*pos), member))

/**
* list_for_each_entry_safe – iterate over list of given type safe against removal of list entry
* @pos:    the type * to use as a loop counter.
* @n:        another type * to use as temporary storage
* @head:    the head for your list.
* @member:    the name of the list_struct within the struct.
*/
#define list_for_each_entry_safe(pos, n, head, member)            \
for (pos = list_entry((head)->next, typeof(*pos), member),    \
n = list_entry(pos->member.next, typeof(*pos), member);    \
&pos->member != (head);                     \
pos = n, n = list_entry(n->member.next, typeof(*n), member))

#endif

在来个Makefile 吐舌头

TARGET=flight_system
SRCS=$(wildcard *.c)
OBJ=$(patsubst %.c, %.o, $(SRCS))
CC=gcc
$(TARGET):$(OBJ)
	$(CC)  $^ -o $@ 
%.o:%.c
	$(CC) -o $@ -c $<	

clean:
	rm *.o $(TARGET)

AI Agent开发核心架构与Google ADK实战指南 AI Agent作为人工智能领域的重要应用形态,其核心架构通常由语言模型、工具系统和协调框架三部分组成。语言模型(如Gemini)负责认知决策,工具系统提供具体功能实现,而框架(如Google ADK)则负责组件协调。这种模块化设计使得开发者可以灵活组合不同AI能力,实现从简单问答到复杂业务流程自动化的各类场景。在工程实践中,ADK框架通过标准化的工具接口、状态管理和任务规划机制,显著降低了Agent开发门槛。特别是在需要动态工具调用和长期状态维护的场景中,如航班查询、智能客服等应用,ADK展现出了相比传统 阅读详情

相关推荐

linux下用C写的简单航班信息查询系统

linux下用C写的简单航班信息查询系统,主要是单向链表,插入排序等算法的使用

航班管理系统

开发工具(eclipse/idea/vscode等): 数据库(sqlite/mysql/sqlserver等): 功能模块(请用文字描述,至少200字):

weixin_45769113的博客 260

基于Linux系统的航班信息与订票系统

通过双向循环链表进行数据存储,可以实现订票,买票,充值,选座位等功能,在管理员用户中,可以修改用户信息,航班信息等

航班系统

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;using System.Data.SqlClient;namespace Wi

武江伟 864

linux下C语言实现的航班管理系统

unbantu 16.4 下用c语言实现的命令形式的航班管理系统,有乘客登录,管理员登录,通过文件保存航班和乘客信息

基于Linux下的航班查询系统

利用文件IO读取指定文件的信息,并存档到链表数据中, 通过链表进行修改,在修改完成后,重新写入文件

Linux 编写C程序

1. 完成一个简单的例子: 用gedit完成helloworld.c的编写 用gcc分为四个步骤:    预处理    编译    汇编    链接 查看结果,并运行该程序。 2. 多文件C语言程序编写 (1)在主目录下新建文件夹stack (2)利用vi编辑器,编写main.c,stack.c,stack.h三个文件,内容分别是: main.c: /*m

离开实践的理论是空洞的理论,没有理论指导的实践是盲目的实践 611

linux C实现飞机订票系统代码

在linux C下实现的飞机订票系统。模块化管理代码,实现了航班信息的浏览,修改,查找,排序,和客户端的订票退票的业务。

航班查询系统项目

嵌入式小项目,前置知识:c语言、数据结构、Linux操作系统。

weixin_64600837的博客 1389

航班查询系统

基于Linux,通过链表,文件IO实现航班查询系统

内核链表航班系统

应用linux内核链表制作航班系统,有添加和删除功能,查询等功能。

【数据结构】航班查询系统:链表的实际运用

方案一(单向链表实现) 文件:flight.c 文件:flight.h 主函数:main.c 方案二(双向链表实现) 文件:flight_cyc.c 文件:flight_cyc.h 文件:main_cyc.c 方案三(内核链表实现) 文件:flight_kernel.c 文件:flight_kernel.h 文件:main_kernel.c 以上代码经过测试,可以直接复制粘贴即可使用,希望该内容对您有帮助,感谢!以上。仅供学习与分享交流,请勿用于商业用途!转载需提前说明。我是一个十分热爱技

猫猫的小茶馆 654

基于linux c 的航班管理系统

主要是c语言学习完之后到数据结构链表这块进行的一个小项目,用到了makefile,静态动态库

嵌入式学习总结

哈喽,大家好!转眼间到了四月中旬,来到咱大华清学习嵌入式课程快两月了。恍恍惚惚的我感觉才过了两周一样,不说了,时间的体验感越来越迷糊了,目前刚结束进程线程的课程。这段时间的收获还是不少的。 从最基础的预科C开始,老师细致入微地讲述每一个知识点,学习了C语言的数据基本类型、运算符、控制流、内存映射、指针、结构体等太多干货。当时写出了人生中第一条C程序,打印了一个hello world语句,当时还是蛮有成就感的。 后面来到Linux基础课程,学会了自己创建一个虚拟机以及ubuntu...

weixin_69475587的博客 4132

【传奇开心果系列】Flet框架实现的窗口屏幕居中示例自定义模板特色和实现原理深度分析

本文介绍了使用Flet框架实现窗口屏幕居中的方法。通过设置page.window.center()方法,程序会自动计算屏幕尺寸和窗口位置实现居中显示。文章建议将任务栏设为自动隐藏以获得更精确的居中效果,并详细分析了Flet窗口管理的实现原理,包括坐标计算、跨平台兼容性等技术细节。该方案提供了简洁的API调用,支持动态调整窗口位置和多显示器环境,源码可通过优快云下载。

jackchuanqi的博客 1200

SIwave串扰分析保姆级教程:从Allegro文件导入到结果解读,手把手教你排查PCB信号问题

本文提供SIwave串扰分析的详细教程,从Allegro文件导入到结果解读,手把手教你排查PCB信号问题。涵盖环境准备、参数配置、串扰扫描技巧及实战案例,帮助工程师精准定位和解决高速PCB设计中的串扰问题,提升信号完整性分析能力。

weixin_42620913的博客 255

Linux内核链表的一点随笔

今天在看linux的内核链表这一章时,看到了很有意思的一个东西,几下来分享下,同时写一点我的看法。 谈到内核链表,在linux源码里我们会看到铺天盖地的链表,内核里有那么多的结构体,那么内核源码是怎么样将这些链表高效的操作的呢。 我觉得内核源码力度额第一个亮点就是这个双向链表struct list_head的设计 #define list_entry(ptr,type,member) ((t

遥远的她 473

大学生电赛学习之路

可以看到全国大学生电子设计大赛的认可度是非常高的,属于A类学科竞赛。电子设计大赛的形式也是给出题目,参赛者有四天三夜的时间解决问题,题目大致可以分为:控制类、测量类、高频类以及电力电子类。该竞赛会在单数年的9月份举行。但是对于新生来说电赛确实遥不可及的,可能在很多学校本科生是不能进入实验室的,但是就算进了实验室你就有资格去参加电赛或者说能拿一个不错的奖项吗? 现在正值新生开学季,当然会有一大批学生会进入实验室的学习,电赛的举办时间是每年的暑假,所以说对于大一同学来说有一年的时间去准备,那我们就来说一说参加.

weixin_46098612的博客 8788

基于Linux购票服务器

/date航班信息文件/register用户注册信息文件/user用户购票信息文件 server #include "head.h" char chars[10]; char sendbuf[1024]; struct list_node{ char name[10];//用户名 char passwd[10];//密码 ch...

weixin_30545285的博客 575

数据库迁移策略实战:MySQL到PostgreSQL

数据库迁移是一项复杂且细致的任务,需要充分的准备工作、合适的迁移策略和严格的验证与优化步骤。通过选择合适的迁移工具、进行手动迁移和应用程序适配、以及迁移后的验证与优化,可以确保数据迁移的成功和业务的连续性。希望本文的分享能够为大家在MySQL到PostgreSQL的数据库迁移实战中提供一些有用的参考和启示。

shejizuopin的博客 1730

[记录一个bug]av_hwdevice_ctx_create出现Cannot allocate memory(附带库运行时路径)[已解决]

新写的程序里调用ffmpeg的av_hwdevice_ctx_create()这个函数,出现Cannot allocate memory。但是另个程序一样的代码,居然是成功的。 反复检查之后无果,就跳出去查了一下,看到一个问答: Have you tried to use ffmpg executables with the same libs that you using when you run the app? Have you tried to use ffmpg executables

熊猫Ben的博客 3585

基于SpringBoot+Vue的航空公司售票系统的设计与实现毕业设计全套源码文档

当前航空公司售票存在流程繁琐、信息不同步等问题:用户购票需多次跳转页面,操作复杂;航班动态变化快,余票信息更新滞后;退改签流程不透明,用户体验差;会员积分管理分散,难以有效激励用户;后台数据统计分析困难,不利于运营决策。 基于 SpringBoot+Vue 的航空公司售票系统,依托前后端分离架构优势,整合核心功能:航班信息实时查询与筛选(按时间、价格、航空公司等)、便捷购票流程(一键下单、多种支付方式)、智能退改签管理(自动计算费用、在线操作)、会员积分体系(累计、兑换、等级权益)、订单全生命周期跟踪、后台

专注于大学生项目实战开发,讲解,毕业答疑辅导,高校老师/讲师/同行合作。以及产品测评宣传、工具推广等合作。全网粉丝30万+,优快云特邀博主,Java新星计划多届导师,掘金/知乎/华为云/阿里云/51CTO等平台优质创作者。 987

如何将rvt(BIM)转换为点云格式

1、为什么将BIM转换为点云格式? 如何使设计BIM与真实场景进行配准,分析在建、未建、已建构建的情况,真实场景是通过点云生产的,和点云配准需要相同的格式。 2、如何转换? 实用工具revit,转换过程如下图,这样就可以转换成三角网格形式。 3、FBX还需要进行一次转换,即转换成点云常用的类型,如bin\ply\pcd等格式。 需要软件cloudcompare.exe,软件下载地址百度云 链接:https://pan.baidu.com/s/1pflcKNc04loBnS1yKR39hw 提取码:obaf

self_Name_的博客 4489

航班信息管理系统_C语言小项目_课程设计_大作业

我的博客已经停更有一段时间了。这段时间先是高烧,然后在忙课程设计......

工业废气 921

【深度学习时间序列预测案例】零基础入门经典深度学习时间序列预测项目实战(附代码+数据集+原理介绍)

本专栏整理了《深度学习时间序列预测案例》,内包含了各种不同的基于深度学习模型的时间序列预测方法,例如LSTM、GRU、CNN(一维卷积、二维卷积)、LSTM-CNN、BiLSTM、Self-Attention、LSTM-Attention、Transformer等经典模型,包含项目原理以及源码,每一个项目实例都附带有完整的代码+数据集。

优快云 精品推荐 4万+

EtherCAT主站SOEM -- 15 -- CIA402伺服驱动器子协议

以上就是EtherCAT主站SOEM – 15 – CIA402伺服驱动器子协议的内容。有不明白的地方欢迎留言;有建议欢迎留言,我后面编写文档好改进。创作不容,如果文档对您有帮助,记得给个赞。

常驻客栈的博客--嵌入式EtherCAT 2732
上一篇: Linux常用命令
下一篇: linux目录
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值