Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/06/08 12:25
Read: times


 
#156424 - I had one error and type mismatch seen
Responding to: ???'s previous message
After reading your response, I see the inproper call. I modified the routine to the following below and it compiles with no errors. It should have been all chars not ints mixed with chars (my bad). There is one final problem I don't understand yet (just woke up), is that it initializes the array, properly sorts all five.......and then goes back to resort it again......forever, it never breaks out of the sort function.....??? It should return to the main() to then be resorted, but it doesn't come out of the bubblesort sort function for main to tell it to go back and do it again. Here is the recompiled code as described:



void bubbleSort(unsigned char my_array[], unsigned char array_size); //prototype

unsigned char my_array[5] = {9,4,2,8,3}; //my array initialized out of order

void bubbleSort(unsigned char my_array[], unsigned char array_size) //sort it
{
  unsigned char i, j, temp;

  for (i = (array_size - 1); i >= 0; i--)
  {
    for (j = 1; j <= i; j++)
    {
      if (my_array[j-1] > my_array[j])
      {
        temp = my_array[j-1];
        my_array[j-1] = my_array[j];
        my_array[j] = temp;
      }
    }
  }
}

void main (void)//main program
{
										  
while(1)//Loop this section forever
   {    
    	
    bubbleSort(my_array, 5); //sort forever test
	 
	
   }
}


List of 9 messages in thread
TopicAuthorDate
Compile error using a bubble sort            01/01/70 00:00      
   Is the array 'uchar' or is it 'int'? Do not mix.            01/01/70 00:00      
   argument consistency            01/01/70 00:00      
      I had one error and type mismatch seen            01/01/70 00:00      
         more careful with decrement unsigned char            01/01/70 00:00      
         Use different identifiers for global and auto            01/01/70 00:00      
            Yes I saw the corruption...            01/01/70 00:00      
               You can use any type you like.            01/01/70 00:00      
                  thanks guys....            01/01/70 00:00      

Back to Subject List