IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 网络协议 -> 【无标题】 -> 正文阅读

[网络协议]【无标题】

#include<stdio.h> #include<math.h> #include<string.h> #include<stdlib.h> struct books_list { char writer[20];? ? ? ? ? ? ? ? ? ? /作者名/ char title[20]; char ISBN[20];? ? ? ? ? ? ? ? ? ? ? /书名/ char publishinghouse[20];? ? ? ? ? /出版单位/ int? price,borrowed;? ? ? ? ? ? ? ? ? ? ? ? /价格/ struct books_list * next; /链表的指针域/ }; struct books_list * Create_Books_Doc();? ? ? ? ? ? ? /新建链表/ void InsertDoc(struct books_list * head);? ? ? ? ? ? /插入/ void sort_maopao(struct books_list * head );? ? ? ? ? // 排序 void DeleteDoc(struct books_list * head , int num);? /删除/ void Print_Book_Doc(struct books_list * head);? ? ? ? /浏览/ void search_book(struct books_list * head);? ? ? ? ? /查询/ void info_change(struct books_list * head);? ? ? ? ? /修改/ void save(struct books_list * head);? ? ? ? ? ? ? ? ? /保存数据至文件/ /新建链表头节点/ struct books_list * Create_Books_Doc() { struct books_list * head; head=(struct books_list *)malloc(sizeof(struct books_list)); /分配头节点空间/ head->next=NULL;? /头节点指针域初始化,定为空/ return head; } /保存数据至文件/ void save(struct books_list * head) { struct books_list *p; FILE *fp; p=head; fp=fopen(“data.txt”,“w+”); /以写方式新建并打开 data.txt文件/ fprintf(fp," --------编号-------书? 名---------------作? ? 者----------出版社-----------价格? ? \n"); /指针从头节点开始移动,遍历至尾结点,依次输出图书信息/ while(p->next!= NULL) { p=p->next; fprintf(fp,"%-6.6s %-15.10s %-10.10s %-10.10s %-10.10d\n",p->ISBN,p->title,p->writer,p->publishinghouse,p->price); } fprintf(fp,"\n"); fclose(fp); printf("? ? 已将图书数据保存到 data.txt 文件\n"); } void sort_maopao(struct books_list * head ) { struct books_list *tail,*p,*q,*p1,*t; //p1等于head t等于head q保存p的next节点 p1=(struct books_list *)malloc(sizeof (struct books_list)); for(t=head->next;t!=NULL;t=t->next) for(p=head->next,p1=head;p->next!=NULL;p=p->next,p1=p1->next) { if(strcmp(p->ISBN,p->next->ISBN)>0) {? q=p->next->next; tail=p->next; tail->next=NULL; p->next=q; p1->next=tail; tail->next=p; p=p1; } } save(head);? //保存文件 } /插入/ void InsertDoc(struct books_list *head) { /定义结构体指针变量 s指向开辟的新结点首地址 p为中间变量/ struct books_list *s, *p; char flag=‘Y’; /定义flag,方便用户选择重复输入/ p=head; /遍历到尾结点,p指向尾结点/ while(p->next!= NULL) { p=p->next; }? /开辟新空间,存入数据,添加进链表/ while(flag==‘Y’||flag==‘y’) { system(“cls”); p->borrowed=0; s=(struct books_list *)malloc(sizeof(struct books_list)); printf("\n? ? ? ? ? ? ? ? ? ? 请输入图书编号:"); fflush(stdin); scanf("%s",s->ISBN); printf("\n? ? ? ? ? ? ? ? ? ? 请输入图书书名:"); fflush(stdin); scanf("%s",s->title); printf("\n? ? ? ? ? ? ? ? ? ? 请输入图书作者名:"); fflush(stdin); scanf("%s",s->writer); printf("\n? ? ? ? ? ? ? ? ? ? 请输入图书出版社:"); fflush(stdin); scanf("%s",s->publishinghouse); printf("\n? ? ? ? ? ? ? ? ? ? 请输入图书价格:"); fflush(stdin); scanf("%d",&s->price); printf("\n"); p->next=s;? /将新增加的节点添加进链表/ p=s;? /p指向尾节点,向后移/ s->next=NULL; printf("? ? ? ? ? ? ? ? ? ━━━━ 添加成功!━━━━"); printf("\n? ? ? ? ? ? ? ? ? ? ? ? ? 继续添加?(Y/N)😊; fflush(stdin); scanf("%c",&flag); printf("\n"); if(flag==‘N’||flag==‘n’) {break;} else if(flag==‘Y’||flag==‘y’) {continue;} } save(head);? /保存数据至文件/ system(“cls”); return; } /查询操作/ void search_book(struct books_list *head) { struct books_list * p; char temp[20]; p=head; if(headNULL || head->nextNULL) /判断数据库是否为空/ { printf("? ? ? ? ? ? ? ? ? ? ? ━━━━ 图书库为空!━━━━\n"); } else { printf(“请输入您要查找的书名: “); fflush(stdin); scanf(”%s”,temp); /指针从头节点开始移动,遍历至尾结点,查找书目信息/ while(p->next!= NULL) { p=p->next; if(strcmp(p->title,temp)0) { printf("\n图书已找到!\n"); printf("\n"); printf(“编号: %s\t\n”,p->ISBN); printf(“书名: %s\t\n”,p->writer); printf(“作者名: %s\t\n”,p->writer); printf(“出版单位: %s\t\n”,p->publishinghouse); printf(“价格: %.2d\t\n”,p->price); } if(p->nextNULL) { printf("\n查询完毕!\n"); } } } return; } /浏览操作/ void Print_Book_Doc(struct books_list * head) { struct books_list * p; if(headNULL || head->nextNULL)? /判断数据库是否为空/ { printf("\n? ? ? ? ? ? ? ? ? ? ? ━━━━? 没有图书记录!? ━━━━\n\n"); return; } p=head; printf("\n\n\n\t\t编号? ? 书 名? ? ? ? 作 者? ? 出版单位? ? 价格? \n"); /指针从头节点开始移动,遍历至尾结点,依次输出图书信息/ while(p->next!= NULL) { p=p->next; printf("\t\t%-7.6s %-13.10s %-10.10s %-10.10s %d \n",p->ISBN,p->title,p->writer,p->publishinghouse,p->price); } printf("\n"); } /修改操作/ void info_change(struct books_list * head) { struct books_list * p; int panduan=0; /此变量用于判断是否找到书目/ char temp[20]; p=head; printf(“请输入要修改的书名:”); scanf("%s",temp); while(p->next!= NULL) { p=p->next; if(strcmp(p->title,temp)0) { printf("\n? ? ? ? ? ? ? ? ? ? 请输入图书编号:"); fflush(stdin); scanf("%d",p->ISBN); printf("\n? ? ? ? ? ? ? ? ? ? 请输入图书书名:"); fflush(stdin); scanf("%s",p->title); printf("\n? ? ? ? ? ? ? ? ? ? 请输入图书作者名:"); fflush(stdin); scanf("%s",p->writer); printf("\n? ? ? ? ? ? ? ? ? ? 请输入图书出版社:"); fflush(stdin); scanf("%s",p->publishinghouse); printf("\n? ? ? ? ? ? ? ? ? ? 请输入图书价格:"); fflush(stdin); scanf("%d",&p->price); printf("\n"); panduan=1; } } if(panduan0) { printf("\n? ? ? ? ? ? ? ? ? ? ? ━━━━? 没有图书记录!? ━━━━\n\n"); } return; } void book_borrow(struct books_list * head) { struct books_list * p; int panduan=0; /此变量用于判断是否找到书目/ char temp[20]; p=head; printf(“请输入要借的书名:”); scanf("%s",temp); while(p->next!= NULL) { p=p->next; if((strcmp(p->title,temp)0)&&(p->borrowed0)) { p->borrowed=1; panduan=1; printf(“图书已经成功借出\n”); } } if(panduan0) { printf("\n? ? ? ? ? ? ? ? ? ? ? ━━━━? 没有要借阅的图书!? ━━━━\n\n"); } return; } /删除操作/ void DeleteDoc(struct books_list * head) { struct books_list *s,*p;? ? /s为中间变量,p为遍历时使用的指针/ char temp[20]; int panduan; /此变量用于判断是否找到了书目/ panduan=0; p=s=head; printf("? ? ? ? ? ? ? ? ? ? [请输入您要删除的书名]😊; scanf("%s",temp); /遍历到尾结点/ while(p!= NULL) { if(strcmp(p->title,temp)0) { panduan++; break; } p=p->next; } if(panduan1) { for(;s->next!=p;)? ? /找到所需删除卡号结点的上一个结点/ { s=s->next; } s->next=p->next; /将后一节点地址赋值给前一节点的指针域/ free§; printf("\n? ? ? ? ? ? ? ? ? ? ? ━━━━? 删除成功!? ━━━━\n"); } else /未找到相应书目/ { printf("? ? ? ? ? ? ? ? ? ? 您输入的书目不存在,请确认后输入!\n"); } return; } int main(void) { struct books_list * head; int choice; head=NULL; do{ printf("? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \n");? printf("? ? ? ? ? -------------------- 图书管理系统-------------------\n\n"); printf("? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [1]图书信息录入? ? ? ? ? ? ? ? \n\n"); printf("? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [2]图书信息浏览? ? ? ? ? ? ? ? \n\n"); printf("? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [3]图书信息查询? ? ? ? ? ? ? ? \n\n"); printf("? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [4]图书信息修改? ? ? ? ? ? ? ? \n\n"); printf("? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [5]图书信息删除? ? ? ? ? ? ? ? \n\n"); printf("? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [6]图书排序? ? ? ? ? ? ? ? ? ? \n\n"); printf("? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [7]图书借阅? ? ? ? ? ? ? ? ? ? \n\n"); printf("? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? [0]退出系统? ? ? ? ? ? ? ? ? ? \n\n"); printf("? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 请选择:"); fflush(stdin); scanf("%d",&choice); switch(choice) { case 1:? if(headNULL) { head=Create_Books_Doc(); } InsertDoc(head); break; case 2:? Print_Book_Doc(head); break; case 3:? search_book(head); break; case 4 : info_change(head); break;? case 5:? DeleteDoc(head); break; case 6:? sort_maopao(head); break; case 7: book_borrow(head); break;? ? case 0 :? printf("\n"); printf("? ? ? ? ? ━━━━━━━━? 感谢使用图书管理系统? ━━━━━━━━\n"); break; default :? printf("? ? ? ? ? ? ? ? ? ? ? ━━━━ 输入错误,请重新输入!━━━━"); } }while(choice!=0); return 0; }

  网络协议 最新文章
使用Easyswoole 搭建简单的Websoket服务
常见的数据通信方式有哪些?
Openssl 1024bit RSA算法---公私钥获取和处
HTTPS协议的密钥交换流程
《小白WEB安全入门》03. 漏洞篇
HttpRunner4.x 安装与使用
2021-07-04
手写RPC学习笔记
K8S高可用版本部署
mySQL计算IP地址范围
上一篇文章      下一篇文章      查看所有文章
加:2021-12-14 16:19:48  更:2021-12-14 16:20:49 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年10日历 -2024/10/5 6:57:24-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码