| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dont kNow Where this is going wrong??
Hello can neone help me on this.. Dontk now wats wrong with this Binary Search Algorithm..
Im trying to get it to work for my report,, im new to this c stuff....Would apreciate ne help.. Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
enum SearchResult {FOUND, NOT_FOUND};
SearchResult binarySearch(int array[], int key, int low, int high, int *comparisons);
void fill_array(int array[], int sizeOfData);
const int RANGE = 200; // random data used in range 0-199
int main()
{
const int arraySize = 100;
int a[arraySize];
FILE *resultsFile;
resultsFile = fopen("bsrch.dat", "w"); // open the file lsrrch.dat for writing ("w")
if (resultsFile != NULL) // file successfully opened
{
// seed the random number generator so it gives different
// random numbers each time
srand ( time (0) );
// Table headings
printf ("Found\t Data Size\t Comparisons Needed\n" );
//\t puts in a tab character, \n a new line
fprintf (resultsFile, "Data Size\t Comparisons Needed\n" );
fill_array(a, arraySize);
// Generate table for data of different sizes
// giving number of comparisons each time
for (int datasize = 1; datasize <= arraySize; datasize = datasize + 1)
{
int count = 0; // number of comparisons this time
SearchResult result; // result of this search
int searchKey = rand() % RANGE;
result = binarySearch(a, searchKey, 0, datasize -1, &count);
if (result == FOUND)
printf("KEY FOUND \t");
else
printf("NOT FOUND \t");
// print results in a table
printf("%d \t\t\t %d\n", datasize, count);
fprintf(resultsFile, "%d \t\t\t %d\n", datasize, count);
}
|
|
#2
|
||||
|
||||
|
What is going wrong? Cannot compile, or the application does not want you want it to do? The code you pasted is incomplete (probably just missing some closing brackets, and the two forward declared functions) and does not compile directly on my machine either. Also, you want C or C++?
|
|
#3
|
|||
|
|||
|
When i try to compile it it dont work at all.
I can not find where the missing brackets are, so that i can atleast compile it in C. Can you help me with this please. |
|
#4
|
||||
|
||||
|
You're missing a closing brace ( } ) at the very end.
__________________
Officially a member of the Itsacon fan club. Beer blasts are every friday at Viper_SB's house. I bring the chips. ![]() |
|
#5
|
|||
|
|||
|
Quote:
I think he's missing 2. I see three open ( { ) and only 1 closed( } ) |
|
#6
|
||||
|
||||
|
You are also missing the code for the two forward declared functions. Can you post all the code + the full error message your compiler is giving?
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Dont kNow Where this is going wrong?? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|