# btree_locate

> ## Directory

> > eXtremeDB_rt/samples/btree_locate

> ## Description

> > 'locate' demonstrates _locate and _compare cursor operations.

> ## Used API

> > classname_indexname_locate(), classname_indexname_compare()

> ## Code snippet

> >         /* 1. find employee record by name */
> >         rc = Employee_Iname_find(t, search_emp, (mco_uint2)strlen(search_emp), &emp);
> >         if ( MCO_S_OK == rc ) {
> >           printf("\n\n\tFind %s's co-workers :\n", search_emp);
> >           Employee_dept_no_get(&emp, &dept_no);
> >           Employee_Idept_index_cursor(t, &csr);

> >           /* 2. locate cursor in the Idept index */
> >           rc = Employee_Idept_locate(t, &csr, &emp);
> >           if ( MCO_S_OK == rc ) {
> >             while ( MCO_S_OK == rc ) {
> >               /* 3. scroll forward through cursor and display names found... */
> >               rc = mco_cursor_next(t, &csr);
> >               if ( MCO_S_OK == rc ) {
> >                 rc = Employee_Idept_compare(t, &csr, dept_no, &cmp);
> >                 if ( MCO_S_OK != rc || cmp != 0 ) break;
> >                 Employee_from_cursor(t, &csr, &emp2);
> >                 Employee_name_get(&emp2, name, sizeof(name), &len);
> >                 printf("\t%s\n", name);
> >               } else {
> >                 sample_rc_check("\nmco_cursor_next forward loop", rc );
> >               }
> >             }

> ## What to expect as an output

> >         Filling database:

> >     	0) John, Department: 1
> >     	1) Samuel, Department: 1
> >     	2) Thomas, Department: 1
> >     	3) David, Department: 2
> >     	4) James, Department: 2
> >     	5) Robert, Department: 2
> >     	6) William, Department: 3
> >     	7) Kevin, Department: 3
> >     	8) Alex, Department: 3
> >     	9) Daniel, Department: 3
> >     	10) Diego, Department: 3
> >     	11) Brandon, Department: 4

> >     	Find Alex's co-workers :
> >     	Daniel
> >     	Diego
> >     	Kevin
> >     	William