В моем основном файле у меня есть массив символьных строк, имен символов [320] [30], и после того, как я сортирую это с помощью пузырьковой сортировки.Я хочу иметь возможность выполнять рекурсивный бинарный поиск, чтобы определить, присутствует ли слово в массиве имен и каков его индекс.Индекс представлен набором беззнаковых целых без знака int Set [10].Если слово отсутствует, функция должна вернуть -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
}
И в моей основной функции я вызываю функцию:
char *key;
binarySearch(names, key, 0, 319);
Когда я пытаюсь скомпилировать, яполучить следующие ошибки:
- search.c: 7: ошибка синтаксического анализа до "A"
- search.c: в функции `binarySearch ':
- search.c: 7: количество аргументов не соответствует прототипу
- sortAndSearch.h: 3: объявление прототипа
- search.c: 22: `A 'необъявлено (первое использование в этой функции)
- search.c: 22: (Каждый необъявленный идентификатор сообщается только один раз
- search.c: 22: для каждой функции, в которой он появляется.)
- search.c: 22: `key 'undeclared (первое использование в этой функции)
Итак, мой вопрос: почему я получаю эти ошибки, так как не вижу опечаток, и что происходит с количеством не соответствующих аргументов?прототип?Я скопировал его прямо из файла sortAndSearch.h, который мне дали.