1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4
5/*============================================================================
6**
7** Source: test1.c
8**
9** Purpose: Calls bsearch to find a character in a sorted buffer,
10** that does not exist.
11**
12**
13**==========================================================================*/
14
15#include <palsuite.h>
16
17int __cdecl charcmp(const void *pa, const void *pb)
18{
19 return *(const char *)pa - *(const char *)pb;
20}
21
22int __cdecl main(int argc, char **argv)
23{
24
25 const char array[] = "abcefghij";
26 const char missing[] = "0dz";
27 char * found=NULL;
28 const char * candidate = missing;
29
30 /*
31 * Initialize the PAL and return FAIL if this fails
32 */
33 if (0 != (PAL_Initialize(argc, argv)))
34 {
35 return FAIL;
36 }
37
38 while (*candidate) {
39 found = (char *)bsearch(candidate, array, sizeof(array) - 1,
40 (sizeof(char)), charcmp);
41 if (found != NULL)
42 {
43 Fail ("ERROR: bsearch was able to find a specified character '%c' "
44 "in a sorted list '%s' as '%c' "
45 "even though the character is not in the list.\n",
46 *candidate, array, *found);
47 }
48
49 candidate++;
50 }
51
52 PAL_Terminate();
53 return PASS;
54}
55
56
57
58