C语言函数—line

函数名

lfind

功 能

执行线性搜索

用 法

void *lfind(void *key, void *base, int *nelem, int width,

int (*fcmp)());

程序例

#include <stdio.h> 
#include <stdlib.h> 

int compare(int *x, int *y) 
{ 
   return( *x - *y ); 
} 

int main(void) 
{ 
   int array[5] = {35, 87, 46, 99, 12}; 
   size_t nelem = 5; 
   int key; 
   int *result; 

   key = 99; 
   result = lfind(&key, array, &nelem, 
        sizeof(int), (int(*)(const void *,const void *))compare); 
   if (result) 
      printf("Number %d foundn",key); 
   else 
      printf("Number %d not foundn",key); 

   return 0; 
} 
  
  

如果引用本站的原创文章,请注明原文链接:,本站保留追究责任的权利!