sorry to keep harassing you guys but this is hopefully my last question... until next week.
Please take a look at my code (where it says "LOOKY HERE!!!!") and tell me why I am getting this error, thanks:
Code:
error C2664: 'binarySearch' : cannot convert parameter 3 from 'char [30][30]' to 'char []'
Code:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
//Global Variables
ifstream infile;
ofstream outfile;
typedef char string[30];
//Prototypes
void tocaps(string []);
void bubblesort(string [],string [], string [], int);
void cutoff(string []);
void dashinsert(string []);
int binarySearch(string name[],int numel, string key);
void report();
int main()
{
string social[30],phone[30],name[30],key[30];
int i,x;
int numel=22;
char choice;
infile.open("In599A.Dat");
while(!infile.eof())
{
for(i=0;i<23;i++)
{
infile>>social[i]>>phone[i];
infile.getline(name[i],30);
}
}
//Function calls
bubblesort(name,social,phone,numel); //does work
tocaps(name); //does work
//cutoff(name); //does not work
//dashinsert(social); //does not work
infile.close();//closing "In599A.dat"
/*******LOOKY HERE!!!****************/
infile.open("in599B.Dat");
infile >> choice;
cout << choice;
while(infile)
{
for(i=0;i<23;i++)
{
infile.getline(key[i],30);
x=binarySearch(name,numel,key); //does not work
if(x!=-1)
cout << name[x] << endl << '\t';
if(choice=='T')
cout << phone[x] << endl << endl;
if(choice=='S')
cout << social[x] << endl << endl;
if(choice=='B')
cout << social[x] << endl;
cout << '\t' << phone[x];
}
}
infile >> choice;
return 0;
}
void bubblesort(string name[],string social[], string phone[], int numel)
{
int i, j;
string temp;
for(i=0;i<numel-1;i++)
for(j=1;j<numel;j++)
{
if(strcmp(name[j],name[j-1])<0)
{
strcpy(temp,name[j]);
strcpy(name[j],name[j-1]);
strcpy(name[j-1],temp);
strcpy(temp,social[j]);
strcpy(social[j],social[j-1]);
strcpy(social[j-1],temp);
strcpy(temp,phone[j]);
strcpy(phone[j],phone[j-1]);
strcpy(phone[j-1],temp);
}
}
}
void tocaps(string name[])
{
for(int x=0;x<23;x++)
{
for (int y=0;y<strlen(name[x]);y++)
{
name[x][y] = toupper( name[x][y] );
}
}
}
/*void cutoff(string name[])
{
int spccount=0;
char lastname[20], firstname[20], middle[2];
for(int x=0;x<23;x++)
{
for (int y=0;y<strlen(name[x]);y++)
{
//if(name[x][y]==' ')
spccount = 1;
if(name[x][y] == ',')
strncpy(lastname, name[x],y);
//else if((name[x][y] == ' ') && (spccount < 2))
// spccount++;
//else if((name[x][y] == ' ') && (spccount == 2))
//{
// cout << name[x][y] << " " << lastname << "\n";
//}
}
cout << lastname << endl;
}
}*/
void dashinsert(string data[])
{
for(int x=0;x<23;x++)
//if(strlen(data[x])>7)
{
for(int i=0;i<30;i++)
{
data[i][10]=data[i][8];
data[i][9]=data[i][7];
data[i][8]=data[i][6];
data[i][7]=data[i][5];
data[i][6]='-';
data[i][5]=data[i][4];
data[i][4]=data[i][3];
data[i][3]='-';
data[i][11]='\0';
}
cout << endl << data[x];
}
cout << endl;
}
int binarySearch(string name[],int numel, string key)
{int left, right, midpt;
left=0;
right=numel-1;
while(left<=right)
{midpt=(left+right)/2;
if(key==name[midpt])
return midpt;
else if(key> name[midpt])
left=midpt+1;
else
right=midpt-1;
}
return -1;
//if name is not found, output error message "name not found"
}