Hi,

I am trying to get my program to sort a list alphabetically and numerically.

This is the list to sort:
trapezoid 45
triangle 36
circle 10
square 67
oval 56
rectangle 25

This is what I want to print out:
(the list in alphab)
circle 10
oval 56
rectangle 25
square 67
trapezoid 45
triangle 36
(the list numer.)
circle 10
rectangle 25
triangle 36
trapezoid 45
oval 56
square 67


To do this, I stored the data in two arrays, one for the character strings and the other for the numbers. I need to convert the character strings to all caps first to be able to sort the list. I am able to compile my program, but then it does not print out the list out correctly. Is my logic wrong? Can anyone help me?

Here are my functions that I wrote to call in my main program:
Code:
void uppercase(char *shape [25])
{
/*convert all to caps*/
int toupper(char shape);
}
      
void sortalphabetically(char *shape [25], int numbers [], int size)
{
    
/*declaration of variables*/
char temp[50];
int pass, i;

/*sort alphabetically*/
for (pass=0; pass<size; pass++)
  for (i=pass+1; i<size; i++)
    {
    if (strcmp (shape[numbers[pass]], shape[numbers[i]]) >0 )
      /*swap*/
      {
      strcpy(temp, shape[numbers[pass]]);
      strcpy(shape[numbers[pass]], shape[numbers[i]]);
      strcpy(shape[numbers[i]], temp);
      }
   }
}
/*using selection sort method*/
void sortnumerically(char *shape [25], int numbers [], int size)
{
 
/*declaration of variables*/
int i, j, smallestnum, temporary;
 
/*initialization*/
for (i=0; i<size; i++)
  {
  smallestnum=i;
  for (j=i; j<size; j++)
    {
    if ( numbers[smallestnum] > numbers[j] ) 
      {
      smallestnum=j;  
    }
  /*swap*/
  temporary=numbers[i];
  numbers[i]=numbers[smallestnum];
  numbers[smallestnum]=temporary;
  }
}
       
/*print contents in the array*/
void printarray(char *shape [25], int numbers [], int size)
{      
int i;

for (i=0; i<size; i++)
  printf("The sorted list of shapes: %d\n", shape[numbers[i]]);
}