[Dev-C++] Searching through an array - comparing pointers
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Daniel G. <sp...@ho...> - 2003-01-16 10:43:05
|
I'm having trouble with my compare function. The compiler is complaining
that there is no conversion from char** to int. I don't get it!
I've created an array with data and now I want to loop through it until I
find a match for gKey in Array[Here][blank].
#include <iostream>
const char* gKey = "5";
// Forward declaration
int Compare( const char* Check1, char* Check2[41][2] );
int main(int argc, char** argv)
{
// Declare the struct and then initialise the array it contains
struct PAPER
{
char* PaperStrings[41][2];
} PaperTypes, *PaperStruct = &PaperTypes;
int StructSize = sizeof(PaperTypes);
std::cout << StructSize << std::endl;
PaperTypes.PaperStrings[0][0] = "1";
PaperTypes.PaperStrings[0][1] = "Paper Type: Letter";
PaperTypes.PaperStrings[1][0] = "2";
PaperTypes.PaperStrings[1][1] = "Paper Type: Letter(small)";
PaperTypes.PaperStrings[2][0] = "3";
PaperTypes.PaperStrings[2][1] = "Paper Type: Tabloid";
PaperTypes.PaperStrings[3][0] = "4";
PaperTypes.PaperStrings[3][1] = "Paper Type: Ledger";
PaperTypes.PaperStrings[4][0] = "5";
PaperTypes.PaperStrings[4][1] = "Paper Type: Legal";
PaperTypes.PaperStrings[5][0] = "6";
PaperTypes.PaperStrings[5][1] = "Paper Type: Statement";
PaperTypes.PaperStrings[6][0] = "7";
PaperTypes.PaperStrings[6][1] = "Paper Type: Executive";
PaperTypes.PaperStrings[7][0] = "8";
PaperTypes.PaperStrings[7][1] = "Paper Type: A3";
PaperTypes.PaperStrings[8][0] = "9";
PaperTypes.PaperStrings[8][1] = "Paper Type: A4";
PaperTypes.PaperStrings[9][0] = "10";
PaperTypes.PaperStrings[9][1] = "Paper Type: Statement";
PaperTypes.PaperStrings[10][0] = "11";
PaperTypes.PaperStrings[10][1] = "Paper Type: Executive";
// etc.
// Commented out, calling Compare to do search.
// bsearch(gKey, PaperStruct, StructSize, sizeof(char*), Compare(gKey,
PaperTypes.PaperStrings));
Compare(gKey, PaperTypes.PaperStrings);
return 0;
}
// Compare function
int Compare( const char* Check1, char* Check2[41][2] )
{
// Look for a match. Loop until found or Temp = 60
for (int Temp = 0; Temp < (sizeof(*Check2) || 60); Temp++)
{
if (*Check1 == Check2[Temp])
{
std::cout << "\nLookup was completed successfully!!!\n\n" <<
std::endl;
}
else
{
// Do nothing
}
}
return 1;
}
_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
|