1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "Proto.h"
  4.  
  5. int main()
  6. {
  7.     /* Accepts number of elements from user */
  8.     scanf("%d", &elements);
  9.    
  10.     /* Creates dynamic array */
  11.     array = (char *) calloc(elements, sizeof(char));
  12.    
  13.     /* Copies sorted values to the dynamic array */
  14.     for(i = 0; i < elements; i++)
  15.     {
  16.         scanf("%s", &array[i]);
  17.     }
  18.    
  19.     /* Accepts number of elements to search */
  20.     scanf("%d", &search);
  21.    
  22.     /* Searches for elements in sorted array one at a time */
  23.     for(i = 1; i <= search; i++)
  24.     {
  25.         /* Accepts value to search */
  26.         scanf("%s", &value);
  27.        
  28.         /* Resets counter to 0 */
  29.         count = 0;
  30.        
  31.         /* Finds location of element in the sorted list using binary search */
  32.         location = binarySearch(array, value, 0, (elements-1));
  33.        
  34.         /* Checks if element is present in the sorted list */
  35.         if (location == -1)
  36.         {
  37.             printf("%4s not found!\n", value);
  38.         }
  39.        
  40.         else
  41.         {
  42.             printf("%4s found at %4d iteration during iteration %4d\n", value, location, count);
  43.         }
  44.     }
  45.     free(array);
  46. }