CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  基础类

高分求lsearch 源代码!!(100分)

楼主sd01101230(一只蚂蚁)2004-09-03 10:58:17 在 VC/MFC / 基础类 提问

求_lsearch   代码  
   
  是微软c库的,<search.h>  
   
  函数原型   :void   *   _lsearch(const   void   *   key,  
  void   *   base,  
  unsigned   int   *   num,  
  unsigned   int   width,  
  int   (_cdecl   *compare)   (const   void   *   ,const   void   *)  
                );  
  问题点数:100、回复次数:3Top

1 楼sd01101230(一只蚂蚁)回复于 2004-09-04 19:56:34 得分 0

upTop

2 楼Hawk_lp(流浪者)回复于 2004-09-04 20:09:53 得分 100

*  
    *   Copyright   (c)   1989,   1993  
    * The   Regents   of   the   University   of   California.     All   rights   reserved.  
    *  
    *   This   code   is   derived   from   software   contributed   to   Berkeley   by  
    *   Roger   L.   Snyder.  
    *  
    *   Redistribution   and   use   in   source   and   binary   forms,   with   or   without  
    *   modification,   are   permitted   provided   that   the   following   conditions  
    *   are   met:  
    *   1.   Redistributions   of   source   code   must   retain   the   above   copyright  
    *         notice,   this   list   of   conditions   and   the   following   disclaimer.  
    *   2.   Redistributions   in   binary   form   must   reproduce   the   above   copyright  
    *         notice,   this   list   of   conditions   and   the   following   disclaimer   in   the  
    *         documentation   and/or   other   materials   provided   with   the   distribution.  
    *   3.   Neither   the   name   of   the   University   nor   the   names   of   its   contributors  
    *         may   be   used   to   endorse   or   promote   products   derived   from   this   software  
    *         without   specific   prior   written   permission.  
    *  
    *   THIS   SOFTWARE   IS   PROVIDED   BY   THE   REGENTS   AND   CONTRIBUTORS   ``AS   IS''   AND  
    *   ANY   EXPRESS   OR   IMPLIED   WARRANTIES,   INCLUDING,   BUT   NOT   LIMITED   TO,   THE  
    *   IMPLIED   WARRANTIES   OF   MERCHANTABILITY   AND   FITNESS   FOR   A   PARTICULAR   PURPOSE  
    *   ARE   DISCLAIMED.     IN   NO   EVENT   SHALL   THE   REGENTS   OR   CONTRIBUTORS   BE   LIABLE  
    *   FOR   ANY   DIRECT,   INDIRECT,   INCIDENTAL,   SPECIAL,   EXEMPLARY,   OR   CONSEQUENTIAL  
    *   DAMAGES   (INCLUDING,   BUT   NOT   LIMITED   TO,   PROCUREMENT   OF   SUBSTITUTE   GOODS  
    *   OR   SERVICES;   LOSS   OF   USE,   DATA,   OR   PROFITS;   OR   BUSINESS   INTERRUPTION)  
    *   HOWEVER   CAUSED   AND   ON   ANY   THEORY   OF   LIABILITY,   WHETHER   IN   CONTRACT,   STRICT  
    *   LIABILITY,   OR   TORT   (INCLUDING   NEGLIGENCE   OR   OTHERWISE)   ARISING   IN   ANY   WAY  
    *   OUT   OF   THE   USE   OF   THIS   SOFTWARE,   EVEN   IF   ADVISED   OF   THE   POSSIBILITY   OF  
    *   SUCH   DAMAGE.  
    */  
   
  #include   "config.h"  
   
  #include   <stdio.h>  
  #include   <sys/types.h>  
  #ifdef   HAVE_UNISTD_H  
  #include   <unistd.h>  
  #endif   /*   HAVE_UNISTD_H   */  
   
  #include   "compat.h"  
  #include   "emul/search.h"  
   
  #if   defined(LIBC_SCCS)   &&   !defined(lint)  
  static   const   char   sccsid[]   =   "@(#)lsearch.c 8.1   (Berkeley)   6/4/93";  
  #endif   /*   LIBC_SCCS   and   not   lint   */  
  #ifndef   lint  
  static   const   char   rcsid[]   =   "$Sudo:   lsearch.c,v   1.17   2000/03/22   15:53:09   millert   Exp   $";  
  #endif   /*   lint   */  
   
  typedef   int   (*cmp_fn_t)   __P((const   VOID   *,   const   VOID   *));  
  static   VOID   *linear_base   __P((const   VOID   *,   const   VOID   *,   size_t   *,   size_t,  
            cmp_fn_t,   int));  
   
  VOID   *  
  lsearch(key,   base,   nelp,   width,   compar)  
  const   VOID   *key,   *base;  
  size_t   *nelp,   width;  
  cmp_fn_t   compar;  
  {  
  return(linear_base(key,   base,   nelp,   width,   compar,   1));  
  }  
   
  VOID   *  
  lfind(key,   base,   nelp,   width,   compar)  
  const   VOID   *key,   *base;  
  size_t   *nelp,   width;  
  cmp_fn_t   compar;  
  {  
  return(linear_base(key,   base,   nelp,   width,   compar,   0));  
  }  
   
  static   VOID   *  
  linear_base(key,   base,   nelp,   width,   compar,   add_flag)  
  const   VOID   *key,   *base;  
  size_t   *nelp,   width;  
  cmp_fn_t   compar;  
  int   add_flag;  
  {  
  /*   Strict   ANSI   does   not   allow   pointer   arithmetic   on   void   *'s   */  
  const   char   *element,   *end;  
   
  end   =   (const   char   *)   base   +   *nelp   *   width;  
  for   (element   =   (const   char   *)   base;   element   <   end;   element   +=   width)  
  if   (!compar(key,   (VOID   *)   element)) /*   key   found   */  
  return((VOID   *)   element);  
  if   (!add_flag) /*   key   not   found   */  
  return(NULL);  
   
  /*  
    *   The   UNIX   System   User's   Manual,   1986   edition   claims   that  
    *   a   NULL   pointer   is   returned   by   lsearch   with   errno   set  
    *   appropriately,   if   there   is   not   enough   room   in   the   table  
    *   to   add   a   new   item.     This   can't   be   done   as   none   of   these  
    *   routines   have   any   method   of   determining   the   size   of   the  
    *   table.     This   comment   was   isn't   in   the   1986-87   System   V  
    *   manual.  
    */  
  ++*nelp;  
  (void)   memcpy((VOID   *)end,   key,   width);  
  return((VOID   *)   end);  
  }  
   
   
  Top

3 楼sd01101230(一只蚂蚁)回复于 2004-09-05 07:53:12 得分 0

学到了非常关键的技术!!谢谢。明天结分。Top

相关问题

  • 高分求源代码!!
  • 高分求分页源代码!(200分)
  • 高分(100)求BO源代码!
  • 高分求socks 5 server源代码
  • -----高分求Inside Ole的源代码-----
  • ★★★高分求h.263+源代码或库★★★
  • 高分求源代码:窗口问题
  • 高分求跟踪输出源代码
  • 高分求IP电话的源代码
  • -----高分求Chinaren聊天室源代码!---------

关键词

  • nelp
  • lsearch
  • compar
  • lint
  • fn
  • linear
  • cmp
  • const
  • redistributions
  • conditions

得分解答快速导航

  • 帖主:sd01101230
  • Hawk_lp

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo