Thread: Issue with Binary Search function

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    27

    Issue with Binary Search function

    Afternoon guys. I have written the function listed below. It is a binary search function that is supposed to search through a 2d array (dict) for a word (word).

    My issue is that with both strcmp commands, I receive the error "passing argument 1 of 'strcmp' makes pointer from integer without cast." I googled it, but I didn't come up with any concrete answers. Thanks.

    Code:
    int binsearch (char dict[][19], int maxWords, char word) {
    
    int low = 0;
    int high = maxWords-1;
    int FOUND = 0;
    
    while (low <= high) {
    
        int mid = (low + high)/ 2;
    
        if ((strcmp(word,dict[mid])) < FOUND)
            high = mid-1;
    
        else if ((strcmp(word,dict[mid])) > FOUND)
            low = mid+1;
    
        else
            return 1;
    
        }
    
    return 0;
    
    }

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    "word" is a character, not a null-terminated array of characters (string).

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    27
    Thanks. I have changed word to word[]. It's always something small that I've overlooked. Thanks.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Difference Between A Linear Search And Binary Search
    By ImBack92 in forum C Programming
    Replies: 4
    Last Post: 05-12-2011, 08:47 AM
  2. Replies: 1
    Last Post: 04-16-2011, 04:44 AM
  3. binary search function on string array
    By gandolf989 in forum C Programming
    Replies: 6
    Last Post: 10-02-2007, 01:47 PM
  4. A Binary Search Tree of... Binary Search Trees...
    By SlyMaelstrom in forum C++ Programming
    Replies: 5
    Last Post: 12-10-2005, 02:12 PM
  5. binary search and search using binary tree
    By Micko in forum C++ Programming
    Replies: 9
    Last Post: 03-18-2004, 10:18 AM