How to Manipulate & Sort Character Arrays in the APIID: Q140691 3.00 WINDOWS
The information in this article applies to:
SUMMARYThis article gives an example showing how to manipulate FoxPro character arrays in the API. The function mysort in this example takes a one- dimensional array of character information and sorts it using the Machine collation sequence. The sorting mechanism that is used is a simple select sort. This function requires a one-dimensional array of character values.
MORE INFORMATIONThe Xbase component is very simple. It creates a one-dimensional array and then populates it with a non-ordered list of names. Then it displays the array, it calls the sort function from the Library, and displays the array again in sorted order.
Xbase Code Sample* *Begin Program code * CLEAR SET LIBRARY TO MYSORT.FLL DIMENSION marray(5) STORE "ZACH" TO marray(1) STORE "CHRIS" TO marray(2) STORE "ANDY" TO marray(3) STORE "TERRY" TO marray(4) STORE "BOB" TO marray(5) DISPLAY MEMORY LIKE ma* =mysort(@marray) DISPLAY MEMORY LIKE ma* * *End Program codeThe C code used in the library routines is also fairly simple. The main function in the library (the one registered in Visual FoxPro) is mysort. Mysort simply receives an array reference and fills a Locator structure to point to that array. Then it determines if the array is one or two dimensional by using the _ALen() function. Then the _ALen() function is used to determine the number of elements in the array and to set the max value for the last element. SelectSort is a recursive function that receives a pointer to the array and a short that determines the imposed end of the array. SelectSort calls itself until the imposed end of the array is the first element. FindMax receives a pointer to the array and the number of the imposed last element. It assumes that the first element has the maximum value in the array and compares it to the remaining elements to find a higher value. FindMax returns the position of the element with the highest value. The values are compared using the StrCmp() function on the dereferenced pointers to the array elements. Exchange receives a pointer to the array and two short values representing two array elements to swap positions. This function uses _Load() to fill value structures for both elements then uses _Store() to place those values into the other position in the array.
C Code Sample
{
short FindMax(Locator FAR Findloc, short MaxPos)
{
}
{
}
{
}
FoxInfo myFoxInfo[] = { };
FoxTable _FoxTable = {
};
Additional reference words: 3.00 VFoxWin KBCategory: kbhowto KBSubcategory: FxtoolLck
|
Last Reviewed: May 22, 1998 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |