TutPtrAryGetItemIndex


Name

TutPtrAryGetItemIndex — get the array index of the specified item in a pointer array

Synopsis

T_BOOL TutPtrAryGetItemIndex(ptr_ary, item, index) 
T_PTR_ARY ptr_ary; 
T_PTR item; 
T_INT4 *index; 

Arguments

ptr_ary — pointer array searches for the item

item — item to search for in the pointer array

index —pointer to index of the item in the array

Return Values

TRUE if item is found in the array; FALSE otherwise.

Diagnostics

None

Description

TutPtrAryGetItemIndex searches ptr_ary for the first occurrence of item and returns index if the item is found in the array. If the item is not found in the array, TutPtrAryGetItemIndex returns FALSE, and the returned index is undefined. Pointer arrays have a zero-based index.

Caution

Allocate memory for index before calling TutPtrAryGetItemIndex.

See Also

TutPtrAryInsertItemAtIndex

Examples

This example returns the array index of a given item in the array:

T_PTR_ARY ptr_ary; 
T_INT4 i, *int_ptr, *save_ptr, index; 
 
/* create the pointer array with initial size of 30 */ 
 
ptr_ary = TutPtrAryCreate(30); 
/* fill it up with 25 entries */ 
for (i = 0; i < 25; i++) { 
  /* allocate the space for the next element */ 
  T_MALLOC(int_ptr, sizeof(T_INT4), T_INT4 *); 
  *int_ptr = i; 
  /* append the item to the array, ignore the index */ 
  TutPtrAryAppend(ptr_ary, int_ptr, NULL); 
  /* save the pointer to the memory location containing number 13 */ 
     /* for the future */ 
  if (i == 13) { 
  save_ptr = int_ptr; 
  }  
}  
 
/* perform various operations on the array */ 
. 
. 
. 
 
/* now, look up the index of the pointer that points to number 13 */ 
/* in the array */ 
if (TutPtrAryGetItemIndex(ptr_ary, save_ptr, &index)) { 
  /* we were able to find the item in the array */ 
  TutOut("The index of the element is %d \n", index); 
  }  
else { 
  TutOut("The expected element was not found in the array. \n"); 
  TutOut("It was probably removed. \n"); 
  }  

TIBCO SmartSockets™ Utilities
Software Release 6.8, July 2006
Copyright © TIBCO Software Inc. All rights reserved
www.tibco.com