gtpc2mfi | C/C++ Language Support User's Guide |
This function locates and points the cursor at the element with a key or sort field that matches the argument.
Format
#include <c$to2.h> long TO2_locate (const TO2_PID_PTR cursorPidPtr, TO2_ENV_PTR env_ptr, const long *argumentLength, const void *argument);
Normal Return
The normal return is a positive value.
Error Return
An error return is indicated by a zero. When zero is returned, use the TO2_getErrorCode function to determine the specific error code. For more information, see Error Handling.
The following error codes are common for this function:
TO2_ERROR_ENV
TO2_ERROR_LOCATOR_LGH
TO2_ERROR_LOCATOR_NOT_FOUND
TO2_ERROR_METHOD
TO2_ERROR_PID
TO2_ERROR_ZERO_PID
Programming Considerations
Examples
The following example shows how the element is located in the cursor that matches the search key and positions the cursor to point to it.
#include <c$to2.h> /* Needed for TO2 API Functions */ #include <stdio.h> /* APIs for standard I/O functions */ TO2_ERR_CODE err_code; /* TO2 error code value */ TO2_PID cursor; TO2_ENV_PTR env_ptr; /* Pointer to TO2 environment */ u_char argument; long arg_Length;
·
·
·
/***********************************************************************/ /* Locate and point the cursor to the element matching the key. */ /***********************************************************************/ if (TO2_locate(&cursor, env_ptr, &arg_Length, &argument) == TO2_ERROR) { err_code = TO2_getErrorCode(env_ptr); if (err_code == TO2_ERROR_LOCATOR_NOT_FOUND) { printf("There are no elements that match the search criteria.\n"); } else { printf("TO2_locate failed!\n"); process_error(env_ptr); } } else { printf("TO2_locate successful!\n"); }
Related Information