CHSEEK@

Platform

x64, Win32

Purpose

To look for a given string in an ordered array.

Syntax

SUBROUTINE CHSEEK@(ITEM,LIST,N,IRES)
CHARACTER (LEN=*) ITEM,LIST(N)
INTEGER (KIND=3) N,IRES

Description

Seeks the string ITEM in the sorted array LIST using a binary chop. Returns the position in IRES or 0 if not found. Note that the LIST array must be sorted in ascending dictionary order.

Example

PROGRAM FOOD
 CHARACTER(LEN=10)::FOODS(5)
 CHARACTER(LEN=12)::MEAL
 INTEGER::K
 DATA FOODS/'BUTTER','EGGS','FISH','MUTTON','SUGAR'/
 DO READ (*,'(A)') MEAL
  CALL CHSEEK@(MEAL,FOODS,5,K)
  SELECT CASE(K)
   CASE(0) PRINT *,'this is not a food I know about'
   CASE(1) PRINT *,'spread it'
   CASE(2) PRINT *,'boil it'
   CASE(3) PRINT *,'fry it'
   CASE(4) PRINT *,'stew it'
   CASE(5) PRINT *,'put it in coffee'
  END SELECT
 END DO
END PROGRAM FOOD

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited