`
lkj107
  • 浏览: 105341 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

lfind - lsearch

 
阅读更多

lfind - lsearch - Find Key in Array

  •  
      #include <search.h>
      char *lfind(char *search_key, char *base,
                   unsigned int *num, unsigned int *width,
                   int (*compare)(const void *key, const void *element));
      char *lsearch(char *search_key, char *base,
                     unsigned int *num, unsigned int *width,
                     int (*compare)(const void *key, const void *element));
      
    •  
        Meaning
        key and element are different.
        key and element are identical.
    • lfind and lsearch perform a linear search for the value search_key in an array of num elements, each of width bytes in size. Unlike bsearch, lsearch and lfind do not require that you sort the array first. The argument base points to the base of the array to be searched.

      If lsearch does not find the search_key, it adds the search_key to the end of the array and increments num by one. If lfind does not find the search_key, it does not add the search_key to the array.

      The compare argument is a pointer to a function you must supply that takes a pointer to the key argument and to an array element, in that order. Both lfind and lsearch call this function one or more times during the search. The function must compare the key and the element and return one of the following values:

      Value

      Nonzero0

      Note: In earlier releases of C Set ++, lfind and lsearch began with an underscore (_lfind and _lsearch). Because they are defined by the X/Open standard, the underscore has been removed. For compatibility, The Developer's Toolkit will map _lfind and _lsearch to lfind and lsearch for you.

       

      If search_key is found, both lsearch and lfind return a pointer to that element of the array to which base points. If search_key is not found, lsearch returns a pointer to a newly added item at the end of the array, while lfind returns NULL.

      This example uses lfind to search for the keyword PATH in the command-line arguments.
    #include <search.h>#include <string.h>
    #include <stdio.h>
    
    #define  CNT           2
    
    int compare(const void *arg1,const void *arg2)
    {
       return (strncmp(*(char **)arg1, *(char **)arg2, strlen(*(char **)arg1)));
    }
    
    int main(void)
    {
       char **result;
       char *key = "PATH";
       unsigned int num = CNT;
       char *string[CNT] =  {
          "PATH = d:\\david\\matthew\\heather\\ed\\simon","LIB = PATH\\abc" };
    
       /* The following statement finds the argument that starts with "PATH"      */
    
       if ((result = (char **)lfind((char *)&key, (char *)string, &num,
                      sizeof(char *), compare)) != NULL)
          printf("%s found\n", *result);
       else
          printf("PATH not found \n");
       return 0;
    
       /****************************************************************************
          The output should be:
    
          PATH = d:\david\matthew\heather\ed\simon found
       ****************************************************************************/
    }
    

    Syntax

     

    Description

     

    Returns

     

    Example Code

     

    分享到:
    评论

    相关推荐

      vim-eunuch:eunuch.vim:UNIX的帮助程序

      太监最需要UNIX外壳程序命令... :Lfind / :Llocate :和上面一样,但是使用位置列表。 :Wall :编写每个打开的窗口。 方便启动工具。 :SudoWrite :使用sudo编写特权文件。 :SudoEdit :使用sudo编辑特权文件。 sudo -

      linux_c API函数大全

      lsearch(线性搜索) 79 8.5 80 qsort(利用快速排序法排列数组) 80 8.6 81 rand(产生随机数) 81 8.7 81 srand(设置随机数种子) 81 9 文件操作篇 82 9.1 82 close(关闭文件) 82 9.2 82 creat(建立文件) 82 ...

      C标准库源代码(学习C/C++必备)

      C标准库源代码\LSEARCH.C C标准库源代码\LSEEK.C C标准库源代码\LSEEKI64.C C标准库源代码\MAKEFILE C标准库源代码\MAKEFILE.INC C标准库源代码\MAKEFILE.SUB C标准库源代码\MAKEPATH.C C标准库源代码\MALLOC.C C...

      jSP在线教学质量评价系统的设计与实现(源代码)

      在线教学质量评价系统可以方便和全面地收集教师教学工作的数据,提供师生网上评教的评分结果,快速集中收集各方面的评教信息,使教务管理部门能够及时了解教学动态和师资情况,为教务老师提供相关决策支持,为职称评聘提供教学工作质量的科学依据,同时减轻了教务老师的工作量。

      python-3.10.7-amd64.zip

      python-3.10.7-amd64.zip

      自研扩散模型高光谱修复网络

      自研扩散模型高光谱修复网络 基于MST_Plus_Plus 网络改造。 试验数据 扩散模型loss初步测试降到了0.005,比不加扩散loss小了20倍, 训练入口 train_cos_img.py

      企业数据治理之数据安全治理方案.pptx

      企业数据治理之数据安全治理方案

      毕业设计基于Android的一个红外防盗报警源码.zip

      这是历年的毕业设计的项目,基于Android的一个红外防盗报警。需要自己添加蜂鸣器和热释电的硬件访问服务。

      短视频用户价值研究报告2022

      短视频用户价值研究报告2022

      基于springboot的食堂管理系统.zip

      基于springboot的java毕业&课程设计

      50.基于SSM的停车场管理系统的设计与实现-基于SSM+ Mysql+Java设计与实现(可运行源码+数据库+lw)毕业设计管

      可运行源码(含数据库脚本)+开发文档+lw(高分毕设项目) java期末大作业毕业设计项目管理系统计算机软件工程大数据专业 内容概要:首先在日常的出行中,老旧城区道路狭窄,容易造成车辆的堵塞,每天早晚,接送孩子的车辆数密集,会造成相应的交通堵塞情况。而同样的,在停车的管理上,一方面我国的停车场面积较少,停车位一位难求,特别是在现在的一些小区里,为了抢停车位而产生的矛盾也日益突出。另一方面在停车场的管理上也存在着较大的管理问题,进车容易出车难是当下的停车场所出现的主要问题。而现在的停车场管理系统眼花缭乱,效果水平也良莠不齐,停车场的管理是当下各大城市的公共设施发展的一大难题,而国家、各大省市也都开 全套项目源码+详尽文档,一站式解决您的学习与项目需求。 适用人群: 计算机、通信、人工智能、自动化等专业的学生、老师及从业者。 使用场景及目标: 无论是毕设、期末大作业还是课程设计,一键下载,轻松部署,助您轻松完成项目。 项目代码经过调试测试,确保直接运行,节省您的时间和精力。 其他说明: 项目整体具有较高的学习借鉴价值,基础能力强的可以在此基础上修改调整,以实现不同的功能。

      基于SpringBoot的新闻管理发布系统,新闻后台管理系统。.zip

      基于springboot的java毕业&课程设计

      微信小程序设计-金融行业.rar

      微信小程序设计之相关行业源码及图文导入教程

      JAVA泡泡堂网络游戏的设计与实现(源代码+lw).zip

      网络游戏开发是一项很大的工程,需要很多综合性的知识。这对于刚刚入门的开发者来说很难理解。本论文从研究开发一个模仿泡泡堂网络游戏的例子出发,讲述网络游戏开发中用到的一些最基本的知识和设计思想,使大家清晰的理解游戏开发的过程。 整个设计中利用java中的swing编程,结合游戏的操作流程,对整个游戏进行精心的设计和大量的测试,实现游戏软件服务器端和客户端的开发,为玩家提供一个友好美观的操作界面,并添加聊天等功能以增加玩家之间的互动性,此外实现了可编辑场景地图的功能,使得游戏内容的更加丰富,玩家交互性更好,确保了游戏更具有趣味性、灵活性,以满足玩家对这款网络游戏的要求。

      外东洪路中段.m4a

      外东洪路中段.m4a

      软考3333333333

      软考3333333333

      Elasticsearch 的全文搜索功能使用方法

      附件是Elasticsearch 的全文搜索功能使用方法,文件绿色安全,请大家放心下载,仅供交流学习使用,无任何商业目的!

      CosmoChron:一种使用宇宙成因核素和直接年龄限制的多功能年龄深度建模方法matlab代码.zip

      1.版本:matlab2014/2019a/2021a 2.附赠案例数据可直接运行matlab程序。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。

      基于springboot + websocket + html5 canvas打造网络版坦克大战.zip

      基于springboot的java毕业&课程设计

    Global site tag (gtag.js) - Google Analytics