|
��������
lsearch, lfind - ���������������� ����� � ����������
���������
#include <stdio.h> #include <search.h> char *lsearch ((char *) key, (char *) base, nelp, sizeof (*key), compar) unsigned *nelp; int (*compar) ( ); char *lfind ((char *) key, (char *) base, nelp, sizeof (*key), compar) unsigned *nelp; int (*compar) ( );
��������
������� lsearch ������������� ��� ���������� ����������������� ������ � ������������ � ����������, ���������
� ����� �. �����: ��������� ���������������� ��� ���.
�. 3. ����������, �����. - �.: ���, 1978. ������ 6.1,
�������� S.
������� lsearch ���������� ��������� ������ ������� �� ������� ������. ���� ������ �� �������, ��� ����������� � ����� �������. �������� key ��������� �� ������ ������, ������������� � ������� (���� ������). Base ��������� �� ������ ������� �������. Nelp - ��������� �� �����, ���������� ������� ���������� ��������� � �������. ��� ����� �������� ������������� �� �������, ���� � ������� ����������� ������. Compar - ������� ���������, ��������������� ������������� (��������, ������� strcmp). ������� ��������� ���������� � ����� ����������� - ����������� �� ������������ ��������. ��� ������ ���������� ������� ��������, ���� �������� �����, � ��������, �� ������ ����, � ��������� ������.
������� lfind ��������� �� �� �����, ��� � ������� lsearch, �� �� ��������� ������ � ������� ��� ��������� ������, ��������� � ���� ������ ������ ��������� NULL.
����������
��������� �� ���� (key) � �� ������ ������� �������
(base) ������ ����� ��� "��������� �� �������" � ����������������� � ���� "��������� �� ������".
� ���������, �������������� �������� compar, �� ����������� ������ ����������� ������ ����, ������� �������� ������� � ���������� � ������������ ��������� ����� ��������� ������������ ������.
���� ������� lsearch ����������� ��� ������� ��� "��������� �� ������", ������������ �� �������� ������� ��������������� � ���� "��������� �� �������".
������ �������� �������� ���������, ������� ��������� ������� �������� � ����������, ������� TABSIZE, � ������, ������� ELSIZE, � �������� ����������� ������� � �������, �������� ���������.
#include <stdio.h> #include <search.h> #define TABSIZE 50 #define ELSIZE 120 char line [ELSIZE], tab [TABSIZE] [ELSIZE], *lsearch (); unsigned nel = 0; int strcmp (); ... while (fdets (line, ELSIZE, stdin) != NULL && nel < TABSIZE) (void) lsearch (line, (char*) tab, &nel, ELSIZE,strcmp); ...
��. �����
bsearch(3C), hsearch(3C), string(3C), tsearch(3C).
�����������
���� ������� ������ ������ ������, �� ��� �������,
lsearch � lfind, ���������� ��������� �� ����. � ��������� ������ ������� lfind ���������� ������ ���������
NULL, � ������� lsearch ���������� ��������� �� �����,
����������� ������.
��������
���������� ���������� ������������ � ������� ��� ���������� ������ ������� ������ ����� �������� � ��������������� ������������.
|