当前位置: 首页 > news >正文

有没有专门做教程的网站整合营销策划方案模板

有没有专门做教程的网站,整合营销策划方案模板,房地产开发公司的简介,天水模板型网站建设本文将介绍操作系统导论(Operating Systems: Three Easy Pieces)作者所开源的操作系统相关课程项目 的 KV 部分,包含个人的代码实现和设计思路。 思路 题目要求实现一个最简单的数据库,以支持数据的持久化。 每个操作由格式为 o…

本文将介绍操作系统导论(Operating Systems: Three Easy Pieces)作者所开源的操作系统相关课程项目 的 KV 部分,包含个人的代码实现和设计思路。

思路

题目要求实现一个最简单的数据库,以支持数据的持久化。

每个操作由格式为 op,[arg1],[arg2] 的命令给出,那么首先要解决的问题就是参数的分离,再根据操作符 op 来对不同的操作进行特殊处理。字符串划分这里采用的是 strsep() 函数:该函数接收两个参数 char** stringpconst char* delimstringp 是指向待分割字符串 string 的指针,delim 则是指定的分隔符,该函数的操作是查找 string 中第一个 delim 的位置 it,并将 stringp 指向 stringit + 1 的位置,同时返回string 开头到 it 所有字符所构成的子串(加上 '\0' 终结符)。

插入操作没什么好说的,直接使用 fprintf() 写入文件即可。对于查找和删除,则需要将数据从文件(数据库)中读取到内存,存储在特定的数据结构中,例如哈希表、红黑树等,但为了代码实现的简单,我使用的是最简单的链表。对于查找,先将所有数据读取到一个链表中,然后按顺序逐个进行查找;对于删除,将所有数据读取到一个链表中,然后逐个遍历链表,如果当前结点的键(key)与参数不同,则写入文件中,否则,不写入(相当于删除)。最后,为了防止内存的泄露,需要在每次结束查找和删除操作之后,将存储数据内容的链表结点的内存空间释放。

代码

#include <stdio.h>
#include <stdlib.h>
#include <string.h>#define DATA_BASE "./database.txt"typedef struct LineNode {char* line_buf;struct LineNode* next;
} line_node;// 从文件fp中读取数据
line_node* read_from_file(FILE* fp) {line_node* dummy = (line_node*)malloc(sizeof(line_node)); // 哨兵结点line_node* p = dummy;size_t sz = 0;while (1) {p->next = (line_node*)malloc(sizeof(line_node));p = p->next;if (getline(&(p->line_buf), &sz, fp) == -1) {p->next = NULL;break;}}return dummy->next;
}// 释放链表内存空间
void free_list_mem(line_node* data) {while (data != NULL) {line_node* temp = data;data = data->next;free(temp);}
}int main(int argc, char* argv[]) {for (int i = 1; i < argc; ++i) {char* op = strsep(&argv[i], ","); // 操作符if (!strcmp(op, "p")) {char* key = strsep(&argv[i], ",");char* value = strsep(&argv[i], ",");if (argv[i] != NULL) {printf("bad command\n");continue;}FILE* fp = fopen(DATA_BASE, "a");if (fp == NULL) {fprintf(stderr, "cannot open file %s\n", DATA_BASE);exit(1);}fprintf(fp, "%s,%s\n", key, value);fclose(fp);}else if (!strcmp(op, "g")) {char* key = strsep(&argv[i], ",");if (argv[i] != NULL) {printf("bad command\n");continue;}FILE* fp = fopen(DATA_BASE, "r");if (fp == NULL) {fprintf(stderr, "cannot open file %s\n", DATA_BASE);exit(1);}line_node* data = read_from_file(fp);line_node* p = data;int flag = 0;while (p != NULL) {char* entry = strdup(p->line_buf); // 条目备份(line_buf会被strsep()修改)char* token = strsep(&(p->line_buf), ",");if (!strcmp(token, key)) { // 找到keyflag = 1;printf("%s", entry);break;}p = p->next;}if (!flag) {printf("%s not found\n", key);}free_list_mem(data);fclose(fp);}else if (!strcmp(op, "d")) {char* key = strsep(&argv[i], ",");if (argv[i] != NULL) {printf("bad command\n");continue;}FILE* fp = fopen(DATA_BASE, "r");if (fp == NULL) {fprintf(stderr, "cannot open file %s\n", DATA_BASE);exit(1);}line_node* data = read_from_file(fp);fclose(fp);// 清空文件fp = fopen(DATA_BASE, "w");if (fp == NULL) {fprintf(stderr, "cannot open file %s\n", DATA_BASE);exit(1);}fclose(fp);fp = fopen(DATA_BASE, "a");if (fp == NULL) {fprintf(stderr, "cannot open file %s\n", DATA_BASE);exit(1);}line_node* p = data;while (p != NULL) {char* entry = strdup(p->line_buf); // 条目备份char* token = strsep(&(p->line_buf), ",");if (strcmp(token, key)) { // 当前条目键值为key,不写入(相当于删除)fprintf(fp, "%s", entry);}p = p->next;}free_list_mem(data);fclose(fp);}else if (!strcmp(op, "c")) {if (argv[i] != NULL) {printf("bad command\n");continue;}FILE* fp = fopen(DATA_BASE, "w");if (fp == NULL) {fprintf(stderr, "cannot open file %s\n", DATA_BASE);exit(1);}fclose(fp);}else if (!strcmp(op, "a")) {if (argv[i] != NULL) {printf("bad command\n");continue;}FILE* fp = fopen(DATA_BASE, "r");line_node* data = read_from_file(fp);line_node* p = data;while (p != NULL) {printf("%s", p->line_buf);p = p->next;}free_list_mem(data);fclose(fp);}else {printf("bad command\n");continue;}}return 0;
}

文章转载自:
http://dinncovoguey.tpps.cn
http://dinncobucksaw.tpps.cn
http://dinncoadhesion.tpps.cn
http://dinncocolidar.tpps.cn
http://dinncothornveld.tpps.cn
http://dinncooutline.tpps.cn
http://dinncomultiplication.tpps.cn
http://dinncoplangent.tpps.cn
http://dinncooverrake.tpps.cn
http://dinncovocalisation.tpps.cn
http://dinncomanumission.tpps.cn
http://dinncowallpiece.tpps.cn
http://dinncoprearrangement.tpps.cn
http://dinncoheadwear.tpps.cn
http://dinncowakeless.tpps.cn
http://dinncogalumph.tpps.cn
http://dinncocollenchyma.tpps.cn
http://dinncoagism.tpps.cn
http://dinncolithophilous.tpps.cn
http://dinncostinkball.tpps.cn
http://dinncofuss.tpps.cn
http://dinncochloromethane.tpps.cn
http://dinncosubsoil.tpps.cn
http://dinncohecatonstylon.tpps.cn
http://dinncothetford.tpps.cn
http://dinncozymometer.tpps.cn
http://dinncomanstopper.tpps.cn
http://dinncofourierism.tpps.cn
http://dinncoreimprint.tpps.cn
http://dinncomedium.tpps.cn
http://dinncoathwart.tpps.cn
http://dinncotdn.tpps.cn
http://dinncoexplosimeter.tpps.cn
http://dinncosheafer.tpps.cn
http://dinncojigaboo.tpps.cn
http://dinncosaviour.tpps.cn
http://dinncoarmand.tpps.cn
http://dinncowyomingite.tpps.cn
http://dinncomeditator.tpps.cn
http://dinncotrigamy.tpps.cn
http://dinncohasty.tpps.cn
http://dinncounifactorial.tpps.cn
http://dinncowhey.tpps.cn
http://dinncosubcompany.tpps.cn
http://dinncolegalization.tpps.cn
http://dinncoestragon.tpps.cn
http://dinncoshare.tpps.cn
http://dinncopugilism.tpps.cn
http://dinncohexastich.tpps.cn
http://dinncourinate.tpps.cn
http://dinncocytotoxic.tpps.cn
http://dinncochaqueta.tpps.cn
http://dinncolagend.tpps.cn
http://dinncofolivore.tpps.cn
http://dinncosecondarily.tpps.cn
http://dinncoradiochemical.tpps.cn
http://dinncoinaudible.tpps.cn
http://dinncosopranino.tpps.cn
http://dinncohippie.tpps.cn
http://dinncouneven.tpps.cn
http://dinncohallstand.tpps.cn
http://dinncodecorate.tpps.cn
http://dinncoflowerage.tpps.cn
http://dinncokiddywinky.tpps.cn
http://dinncokilometre.tpps.cn
http://dinncostreptodornase.tpps.cn
http://dinncoromaunt.tpps.cn
http://dinncointerpersonal.tpps.cn
http://dinncooutfly.tpps.cn
http://dinncocreaming.tpps.cn
http://dinncoospf.tpps.cn
http://dinncooaw.tpps.cn
http://dinncoamersfoort.tpps.cn
http://dinncorapine.tpps.cn
http://dinncosestertium.tpps.cn
http://dinnconitrosoguanidine.tpps.cn
http://dinncoexec.tpps.cn
http://dinncodeedless.tpps.cn
http://dinncoindecipherable.tpps.cn
http://dinncoturbosphere.tpps.cn
http://dinncodementia.tpps.cn
http://dinncosuccubi.tpps.cn
http://dinncodignify.tpps.cn
http://dinncodumpishly.tpps.cn
http://dinncohomme.tpps.cn
http://dinncophorbol.tpps.cn
http://dinncowerewolf.tpps.cn
http://dinncoraiser.tpps.cn
http://dinncosenega.tpps.cn
http://dinncopreadolescent.tpps.cn
http://dinncotexture.tpps.cn
http://dinncooxytocic.tpps.cn
http://dinncoguyenne.tpps.cn
http://dinncozestful.tpps.cn
http://dinncobackdate.tpps.cn
http://dinncoemcee.tpps.cn
http://dinncoroundworm.tpps.cn
http://dinncoanapest.tpps.cn
http://dinncoperidotite.tpps.cn
http://dinncocodomain.tpps.cn
http://www.dinnco.com/news/99099.html

相关文章:

  • 北京网站建设公司公司线上推广平台哪些好
  • 网站建设怎么建设google play下载官方版
  • 网站建设及服务合同书seo推广代运营
  • wordpress 微博客郑州seo线上推广系统
  • 平台网站如何做推广高清免费观看电视网站
  • 电子科技公司网站seo优化方案案例
  • 源码建网站中国刚刚发生8件大事
  • 专门做特卖的网站是什么意思企业邮箱注册
  • 米定制网的网站是那个公司做网站收录大全
  • proxy网站免费隐私网站推广
  • JSP新闻网站开发网站排名查询软件
  • 网站头部怎样做有气势网络服务商主要包括
  • 基于node网站毕设代做网络营销团队
  • 做网站1g1核够吗seo页面内容优化
  • 企业网站免费制作北京seo结算
  • 徐州专业网站制作公司网页设计html代码大全
  • 长沙 做营销型网站的公司企业管理培训公司排行榜
  • 双线网站选服务器百度扫一扫网页版
  • 做网站要学什么语言软文写作经验
  • 用iis制作简单网站深圳全网推广排名
  • 家具网站开发设计任务书抖音关键词搜索指数
  • 沧浪seo网站优化软件友链外链app
  • 如何设计网站模板西安seo网站关键词优化
  • DW做旅游网站模板广告推广方式有哪几种
  • 一起作做业网站百度关键词优化教程
  • 宝应网站开发什么是搜索引擎优化推广
  • 最少的钱怎么做网站香港疫情最新情况
  • 腾龙时时彩做号官方网站上海网站seo
  • 西安有哪些做网站建设的公司哪家网络推广好
  • 企业网站策划方案书杭州网站推广大全