Previous Topic

Next Topic

GetKey

Search index file for entry equal to target value.

Short Name

EQLKEY()

Type

Low-level index file function

Declaration

LONG GetKey(COUNT keyno, pVOID target) 

Description

GetKey() searches index file number keyno for an entry equal to the key value pointed to by target.

Return

If GetKey() finds an exact match for target, then it returns the data record position associated with the entry. If an exact match is not found, or if an error occurs, then GetKey() returns a zero, and the global variable uerr_cod is set to the appropriate value. See “c-tree Plus Error Codes” in the c-tree Plus Programmer’s Reference Guide for a complete listing of valid c-tree Plus error values.

Example

LONG      recbyt;
COUNT     keyno;
TEXT      target[11];

scanf("%10s %d",target,&keyno);
if (!(recbyt = GetKey(keyno,target))) {
    if (uerr_cod)
        printf("\nError while searching.");
    else
        printf("\nKey value not found.");
}
else
    printf("\nKey value is in record at position %ld.", recbyt);

Limitations

c-tree Plus will not pad the target key value. Ensure that target points to a properly formed key value. This function is not appropriate for indices allowing duplicates. Use a function from below in that case.

See also

GetGTEKey(), GetGTKey(), GetLTEKey(), GetLTKey()