Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7505651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:59:01+00:00 2026-05-29T21:59:01+00:00

I have a binary search function I am passing a pointer character array, the

  • 0

I have a binary search function I am passing a pointer character array, the length of that array, a search pointer character array and another counter for something else.

int binarySearch(char* charArray, int len, char* searchItem, int counter)
{
    int position;
    int begin = 0;
    int end = len-1;
    int cond =0;


    while(begin <= end)
    {

    position = (begin + end)/2;

    // searchItem is a pointer array and the value I want to compare to is
    // at the index of counter (determined outside of this function)

    if((cond = strcmp(&charArray[position], &searchItem[counter])) == 0)
    {
        return position;
    }
    else if(cond < 0){
        begin = position + 1; 
    }

    else
        end = position - 1;
    }

return -1;
}

From here, going through the code by hand seems to make me want to think it should work fine, however it doesn’t. I think I’m getting thrown off somewhere along the lines of my pointers and how I’m referring to them so the wrong data is being compared.

I’ve looked at it for too long now… really need some help here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:59:03+00:00Added an answer on May 29, 2026 at 9:59 pm

    It is not very clear what is being searched in what. But I’m guessing that you are searching for a character in a sorted character array. If that is the case, you can’t use a strcmp. Instead you can do:

    if(cond = (charArray[position] - *searchItem) == 0)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

1-)For sorted array I have used Binary Search. We know that the worst case
I have a PHP script that builds a binary search tree over a rather
I am writing a delete member function for a Binary Search Tree. I have
Is there a library function that performs binary search on a list/tuple and return
I have a Binary Search Tree that I'm making and I implemented the Insert
I have a binary search loop which gets hit many times in the execution
I have a scenario where I need to search from many binary files (using
I have binary data in a file that I can read into a byte
If you have binary strings (literally String objects that contain only 1's and 0's),
I have a binary file that I have to parse and I'm using Python.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.