嵌入式编程——数据结构与linux编程

server/2025/2/22 1:30:53/

根据dict.txt文件中的内容,用户输入单词获得单词含义
        

#include "public.h"int main(void)
{struct list_head *parray = NULL;FILE *fp = NULL;char *nret = NULL;char *pword = NULL;char *pparaphrase = NULL;int num = 0;char str[1024] = {0};char word[256] = {0};fp = fopen("./dict.txt", "r");if(fp == NULL){ERR_MSG("打开失败\n");return -1;}parray = create_hashtable();while(1){nret = fgets(str, sizeof(str), fp);{if(nret == NULL){break;}}pword = str;pparaphrase = str;while(1)//定位单词{if(*pparaphrase == ' '){*pparaphrase = '\0';break;}pparaphrase++;}while(1)//定位释义{pparaphrase++;if(*pparaphrase != ' '){break;}}insert_hashtable(parray, pword, pparaphrase);}//show_hashtable(parray);while(1){printf("输入1查询单词 任意键数字退出\n");scanf("%d", &num);getchar();if(num == 1){printf("请输入要查询的单词\n");gets(word);if(find_hashtable(parray, word) != NULL){printf("%s \n", find_hashtable(parray, word)->paraphrase);}else{printf("未找到\n");}}else{break;}}destroy_hashtable(parray);parray = NULL;fclose(fp);return 0;
}

#ifndef __PUBLIC_H__
#define __PUBLIC_H__#include "list.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include <errno.h>
#include <error.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#include <time.h>//结构体
typedef struct hashnode 
{struct list_head node;char word[128];char paraphrase[1024];
}hashnode_t;//打印出错信息
#define ERR_MSG(message) do { \printf("[%s%7d]%s:%s\n", __FILE__, __LINE__, message, strerror(errno)); \
}while (0)//更新开始计时时间
#define GET_START_TIME      do { \gettimeofday(&starttime, NULL); \
} while (0)//更新结束计时时间
#define GET_END_TIME      do { \gettimeofday(&endtime, NULL); \
} while (0)//获得耗时时间
#define GET_CONST_TIME  (((endtime.tv_sec * 1000000 + endtime.tv_usec) - (starttime.tv_sec * 1000000 + starttime.tv_usec)) / 1000.0)//哈希结构体参数
#define MAXNUM      52//声明extern struct list_head *create_hashtable(void);
extern int insert_hashtable(struct list_head *pheadlist, char *pstr, char *pstd);
extern int show_hashtable(struct list_head *pheadlist);
extern hashnode_t *find_hashtable(struct list_head *pheadlist, char *pstr);
extern int delete_hashtable(struct list_head *parray, char *pstr);
extern int destroy_hashtable(struct list_head *parray);struct timeval starttime;
struct timeval endtime;#endif


http://www.ppmy.cn/server/169717.html

相关文章

星途汽车掉队?2024销量增速回落,“星纪元”序列后劲不足

近日&#xff0c;奇瑞集团旗下的星途汽车召开了2025商务年会&#xff0c;勾勒了“科技新豪华三步走”的未来规划&#xff0c;宣布将锚定“3大目标、5大超越、3大满意”开启加速奔跑模式。 “技术奇瑞、品质奇瑞、国际化奇瑞,最终都要汇聚成星途星纪元品牌的向上”&#xff0c;…

html - - - - - modal弹窗出现时,页面怎么能限制滚动

html - - - - - 弹出出现时&#xff0c;页面怎么能限制滚动 1. 全局添加css样式2. 更改弹窗状态时的操作 1. 全局添加css样式 .no-scroll {overflow: hidden;height: 100vh; /* 防止移动端地址栏隐藏导致的页面跳动 */ }2. 更改弹窗状态时的操作 if(show){// 打开弹窗&#…

midjourney 一 prompt 提示词

midjourney 不需要自然语言的描述&#xff0c;它只需要关键词即可。 一个完整的Midjourney prompt通常包括三个部分 图片提示&#xff08;Image Prompts&#xff09;、文本提示&#xff08;Text Prompt&#xff09;和参数&#xff08;Parameters&#xff09;。 1、图片提示(…

HTTP 协议(Ⅲ)

目录 一、HTTP 协议概念 二、无状态协议 三、HTTP1.0 & HTTP1.1 四、请求协议和响应协议 五、请求协议 1.浏览器监视请求和响应 2. HTTP请求 2.1 请求的结构 2.2 GET请求 2.3 POST请求 3. HTTP响应 3.1 响应的结构 3.2 常见响应头字段 3.3 常见状态码 4. 请求…

React进阶之前端业务Hooks库(一)

前端业务Hooks库 项目结构实现useToggleuseToggle/index.ts单测packages/hooks/src/\_test_/index.test.tspackages/hooks/src/useToggle/\_tests_/index.test.ts打包实现gulp打包gulpfiles.js根目录/gulpfile.jswebpack打包webpack.config.jspackages/hooks/package.json使用e…

tailwindcss 前端 css 框架 无需写css 快速构建页面

版本&#xff1a;VUE3 TS 框架 vite 文章中使用tailwindcss 版本&#xff1a; ^3.4.17 简介&#xff1a; Tailwind CSS 一个CSS 框架&#xff0c;提供组件化的样式&#xff0c;直接在HTML 中编写样式&#xff0c;无需额外自定义CSS &#xff0c;快速&#xff01; 简洁&#…

网络安全的坚固盾牌· FireEye

FireEye 网络安全的核心是多向量虚拟执行 &#xff08;MVX&#xff09; 和智能驱动分析 &#xff08;IDA&#xff09; 技术。MVX 是一种无特征码的动态分析引擎&#xff0c;可检查可疑的网络流量&#xff0c;以识别逃避传统基于签名和策略的防御的攻击。IDA 是上下文动态规则引…

【Python爬虫(13)】解锁动态网页爬取:从原理到实战

【Python爬虫】专栏简介&#xff1a;本专栏是 Python 爬虫领域的集大成之作&#xff0c;共 100 章节。从 Python 基础语法、爬虫入门知识讲起&#xff0c;深入探讨反爬虫、多线程、分布式等进阶技术。以大量实例为支撑&#xff0c;覆盖网页、图片、音频等各类数据爬取&#xff…