Many of the ISAM functions perform operations relative to a particular index. Therefore an index handle must be passed to the function to identify which index to use. The ihandle function is called to get the handle for an index. It requires a single argument, the name of the index. The return value is an index handle if successful, or NULL if an error occurs.
The ifindkey function is called to find a record matching a particular key value. It requires three arguments, the database handle, the index handle, and the key value. The key value is a list of values for the fields that comprise the index. In the case of the "Author_Index", the key value is the author's last name followed by the first name. The ifindkey function returns I_FOUND if a record matching the key is found, I_NOTFOUND if a matching record is not found, or I_ERROR if an error occurs. If the record is found, then it becomes the current record for the specified index.
The following example program attempts to find a record in the BOOKS database that matches a specified author's name. If the record is found, it becomes the current record for the "Author_Index". The igetrec function is then called to read the current record. It requires four arguments, the database handle, the index handle, an array of pointers that igetrec initializes to point to the field values, a buffer where igetrec stores the actual field values, and finally the size of the buffer. The array of pointers to field values must be one greater than the number of fields in each record. The igetrec function initializes the last field pointer to NULL to indicate the end of the list of field values. The return value is I_OK if the record is successfully read.
Notice that the ifindhead function is called to find the first record in the database, as ordered by the author index. If the return value of ifindhead is not I_OK, it is assumed that the database is empty. If the database is not empty, the showdb function is called to display the field values of each record in the database.