Help with sorting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gemacjr1201
    New Member
    • Nov 2006
    • 14

    #1

    Help with sorting

    Code:
    void SortArray (char names[MAXNAMES][LISTLENGTH]) 
         {
         bool swap;
         int temp[LISTLENGTH];
    
         do
    	{
    	swap=false;
    	for (int i=0; i<MAXNAMES-1; i++)
    		{
    		if (strcmp(names[i][0],names[i+1][0])>0)
    			{
    			for (int j=0; j<LISTLENGTH; j++)
    				{
    				temp[j]=names[i][j];
    				names[i][j]=names[i+1][j];
    				names[i+1][j]=temp[j];
    				swap=true;
    				}
    			}
    		
    		}
    	     } while(swap);
    	}
    It says it can't compare a char to a const cher. ANY IDEAS?
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    When you type

    Code:
    strcmp(names[i][0], names[i+1][0]);
    you are trying to compare the first character of the ith and i+1th name. strcmp, however, compares to character arrays; you should write

    Code:
    strcmp(names[i], names[i+1]);
    instead.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Originally posted by gemacjr1201
      [CODE]It says it can't compare a char to a const cher. ANY IDEAS?
      Actually what it says is "can't convert char to const char *", please try to report your errors acurately.

      See Ganons post for the solution.

      Comment

      Working...