Selection sort problem

This is a discussion on Selection sort problem within the C++ Programming forums, part of the General Programming Boards category; sorry to keep harassing you guys but this is hopefully my last question... until next week. Please take a look ...

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    81

    Selection sort problem

    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"
    }

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    70

    >int binarySearch(string name[],int numel, string key);


    The third parameter in above function declaration is of type string ( char[30])


    >string social[30],phone[30],name[30],key[30];


    In above statement you have declared 'key' parameter as array of string type

    Now when you call

    >x=binarySearch(name,numel,key);


    Your third parameter is array of string while in declaration you have mentioned it as only string parameter ( not as array of string)

    That is the problem !!!!!!!!!!
    Chintan R Naik

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 01-17-2009, 09:48 PM
  2. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 04:03 AM
  3. heap sort problem
    By Cpro in forum C++ Programming
    Replies: 2
    Last Post: 02-04-2008, 03:54 AM
  4. Replies: 5
    Last Post: 11-07-2005, 10:34 PM
  5. Replies: 0
    Last Post: 02-05-2002, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21