C Sequential Search


#include<stdio.h>
/*  w  ww .  j  a  va 2  s  .c  o m*/
int sequential_search(char *items, int count, char key)
{
  register int t;

  for(t=0; t < count; ++t)
    if(key == items[t]) return t;
  return -1; /* no match */
}

int main(void){
   char *str = "asdf";
  
   int index = sequential_search(str, 4, 's');
  
   printf("%d",index);

}

The code above generates the following result.





















Home »
  C Language »
    Data Structures »




Data Structure
Algorithms