lsearch

Section: C Library Functions (3)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

lfind, lsearch - 配列を線形検索する  

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#include <search.h>

void *lfind(size_t *n, size_t size;
            const void key[size],
            const void base[*n * size],
            size_t *n, size_t size,
            typeof(int (const void [size], const void [size]))
                *compar);
void *lsearch(size_t *n, size_t size;
            const void key[size],
            void base[*n * size],
            size_t *n, size_t size,
            typeof(int (const void [size], const void [size]))
                *compar);
 

説明

lfind() and lsearch() perform a linear search for key in the array base which has *n elements of size bytes each. The comparison function referenced by compar is expected to have two arguments which point to the key object and to an array member, in that order, and which returns zero if the key object matches the array member, and nonzero otherwise.

If lsearch() does not find a matching element, then the key object is inserted at the end of the table, and *n is incremented. In particular, one should know that a matching element exists, or that more room is available.  

返り値

lfind() の返り値は、配列のマッチしたメンバーへのポインターである。 もしマッチするメンバーが見つからないと NULL を返す。 lsearch() の返り値も、配列のマッチしたメンバーへのポインターである。 マッチするメンバーが見つからなかったときは、 新たにつけ加えたメンバーへのポインターを返す。  

属性

この節で使用されている用語の説明については、 attributes(7) を参照。
インターフェース属性値
lfind(), lsearch() Thread safetyMT-Safe
 

標準規格

POSIX.1-2008.  

歴史

POSIX.1-2001, SVr4, 4.3BSD. libc-4.6.27.  

バグ

関数の名前の選び方がよくない。  

関連項目

bsearch(3), hsearch(3), tsearch(3)


 

Index

名前
ライブラリ
書式
説明
返り値
属性
標準規格
歴史
バグ
関連項目

This document was created by man2html, using the manual pages.