Searching: The Sequential Search : Sequential Search « Search Sort « C Tutorial






#include<stdio.h>

  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);
 
  }
1








15.7.Sequential Search
15.7.1.Searching: The Sequential Search