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 7690233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:20:57+00:00 2026-05-31T20:20:57+00:00

In my main file I have an array of character strings, char names[320][30], and

  • 0

In my main file I have an array of character strings, char names[320][30], and after I sort that with a bubble sort. I want to be able to do a recursive binary search to determine if a word is present in the names array and what its index is. The index is represented by a set of unsigned ints, unsigned int Set[10]. If the word is not present, the function should return -1.

#include "set.h"
#include "sortAndSearch.h"
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int binarySearch(Char A[][30], char *, int, int){
//this gets passed the global array names
//and the spot we're looking for is the char pointer
//other 2 ints are low = 0, and high = 319
//then it finds mid, a point between high and low
//and then does the same thing on whichever half it needs
//until it finds the index its looking for
//this is recursive because of the low and high values provided

int mid, low, high, result;

//calculate midpoint to cut set in half
mid = (high + low)/2;

//comparison
result = strcmp(A[mid], key);

//if result < 0, A[mid] < key
if(result < 0)
        return binarySearch(A, key, mid+1, high);

//if result > 0, A[mid] > key
else if(result > 0)
        return binarySearch(A, key, low, mid-1);

//if result == 0, A[mid] == key
else if(result == 0)
        return mid;

//couldnt find it
else
        return -1;

//this should return int, either
//the index where the string being searched for is stored in the array
//or -1 to indicate that the string beinng sought is not in the array
}

And in my main function, I call the function:

char *key;
binarySearch(names, key, 0, 319);

When I try to compile, I get the following errors:

  • search.c:7: parse error before “A”
  • search.c: In function `binarySearch’:
  • search.c:7: number of arguments doesn’t match prototype
  • sortAndSearch.h:3: prototype declaration
  • search.c:22: `A’ undeclared (first use in this function)
  • search.c:22: (Each undeclared identifier is reported only once
  • search.c:22: for each function it appears in.)
  • search.c:22: `key’ undeclared (first use in this function)

So my question is why am I getting these errors, as I do not see any typos, and what’s up with the number of arguments not matching prototype? I copied it right from the sortAndSearch.h file I was given.

  • 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-31T20:20:58+00:00Added an answer on May 31, 2026 at 8:20 pm
    int binarySearch(Char A[][30], char *, int, int){
    

    That Char should probably be char (C is a case-sensitive language). Because this was wrong, most of the other compilation errors are consequences of the compiler being confused.

    You also need to give names to the other arguments in a function definition:

    int binarySearch(Char A[][30], char *key, int low, int high){
    

    You then don’t need low and high as separately declared local variables (indeed, you aren’t allowed to declare them as local variables as well as parameters).

    There is also a bug in the logic in the function, I believe:

    if (result < 0)
            return binarySearch(A, key, mid+1, high);
    else if (result > 0)
            return binarySearch(A, key, low, mid-1);
    else if (result == 0)
            return mid;
    else
            return -1;
    

    All values are either greater than, less than, or equal to zero; the else clause is redundant.

    However, you also have a problem with terminating your search. You need to check whether low is greater than high before computing mid, and you should then return the -1 for not found if the range to be searched is empty.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a javascript file main.js and five html files 1.html,2.html,3.html,4.html,5.html I want to
I have a code that looks like this: int main () { fstream file;
In Yii, I have enabled APC caching through the config/main.php file: 'cache' => array(
I have a question regarding passing a variable that is a char array from
So I have a main.py file inside /home/richard/projects/hello-python directory: import sys sys.path.append('/home/richard/projects/hello-python') from Encode
I have a xml file main.xml with following markup and data. main.xml <xml> <content>
I have a situation where my main SWF file loads many external SWF files.
If I have a whole bunch of requires in my main app file: require
In my main CSS file, I have my a:link selector set to display links
I have three files, a main .cpp file: #include <stdio.h> #include myClass.h int main()

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.