home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************\
- ** **
- ** WW WW IIIIIIII NNN NN DDDDDDD BBBBBBB AA SSSSSS EEEEEEEE **
- ** WW W WW II NNNN NN DD DD BB BB AA AA SS EE **
- ** WW W WW II NN NN NN DD DD BBBBBBB AAAAAAAA SSSSSS EEEEEE **
- ** WW W WW II NN NNNN DD DD BB BB AA AA SS EE **
- ** WWWWW IIIIIIII NN NNN DDDDDDD BBBBBBB AA AA SSSSSS EEEEEEEE **
- ** **
- ** SSSSSS OOOOOO FFFFFFFF TTTTTTTT WW WW AA RRRRRRR EEEEEEEE **
- ** SS OO OO FF TT WW W WW AA AA RR RR EE **
- ** SSSSS OO OO FFFFF TT WW W WW AAAAAAAA RRRRRRR EEEEEE **
- ** SS OO OO FF TT WW W WW AA AA RR RR EE **
- ** SSSSSS OOOOOO FF TT WWWWW AA AA RR RR EEEEEEEE **
- ** **
- *********** NOTICE ************************************************************
- ** This file contains valuable trade secrets and proprietary **
- ** assets of Windbase Software Inc. Embodying substantial **
- ** creative efforts and confidential information. Unauthorized **
- ** use, copying, decompiling, translating, disclosure or **
- ** transfer, of any kind, is strictly prohibited. **
- ** **
- ** COPYRIGHT (C) 1992, 1993, 1994. Windbase Software Inc. **
- ** ALL RIGHTS RESERVED. **
- \*****************************************************************************/
-
- #include <stdio.h>
- #include <malloc.h>
- #include <string.h>
- #ifdef HAS_UNISTD_H
- # include <unistd.h>
- #else
- # include <stdlib.h>
- #endif
-
- #include "../memsl.h"
-
- #ifdef WBSTDC
- int Compare(char **item1, char **item2)
- #else
- int Compare(item1, item2)
- char **item1;
- char **item2;
- #endif
- {
- WBTrcEntry(0,"Compare",("%s, %s",*item1?*item1:"NULL",*item2?*item2:"NULL"));
-
- WBTrcReturn(0,strcmp(*item1,*item2),("%d",strcmp(*item1,*item2)));
- }
-
- #if defined(WBTRC_LEVEL1) || defined(WBTRC_LEVEL2)
- #ifdef WBSTDC
- int main(int argc, char **argv)
- #else
- int main(argc, argv)
- int argc;
- char **argv;
- #endif
- #else
- #ifdef WBSTDC
- int main(void)
- #else
- int main()
- #endif
- #endif
- {
- WBARRAY *array;
- FILE *file;
- char **strarray, **strptr;
- int i = 0, i2;
-
- WBTrcMainEntry();
-
- if ((array = WBArrayOpen(NULL,"200,21")) != NULL)
- {
- strarray = (char **) WBArrayArray(array);
- if ((file = fopen("data.dat","r")) != NULL)
- {
- while (i < 200 && fgets(strarray[i],20,file))
- {
- if (*strarray[i])
- if (strarray[i][strlen(strarray[i])-1] == '\n')
- strarray[i][strlen(strarray[i])-1] = '\0';
- i++;
- }
- fclose(file);
-
- printf("**************************** unsorted\n");
- for (i2 = 0; i2 < i; i2++)
- printf("%s\n",strarray[i2]);
-
- printf("**************************** qsort()\n");
- qsort((void *)strarray,i,sizeof(char *),
- #ifdef FUNCTCAST
- (int (*)(const void *, const void *))Compare);
- #else
- (int (*)())Compare);
- #endif
-
- printf("**************************** sorted\n");
- for (i2 = 0; i2 < i; i2++)
- printf("%s\n",strarray[i2]);
-
- printf("**************************** bsearch\n");
- strptr = (char **) bsearch(&strarray[10],(void *)strarray,i,sizeof(char *),
- #ifdef FUNCTCAST
- (int (*)(const void *, const void *))Compare);
- #else
- (int (*)())Compare);
- #endif
-
- if (strptr)
- printf("Found: %s\n",*strptr);
- else
- printf("ERROR: Did not find: %s\n",strarray[0]);
- }
- WBArrayClose(array);
- }
- WBTrcReturn(0,0,("0"));
- }
-