You have the right idea with the commented out line
Code:
//colorVal [walk +1] = colorVal[walk];
But that is only part of sorting colorVal too. You also have to have a hold for colorVal.
Code:
void SortString(char *colorName[], int colorVal[], int index)
{
int curr;// the index start at the second elenment from the left in the array of pointer
int walk; // the index at the element want to compares
char *hold; // pointer to the string you want to compare with
char *temp; // pointer to the the next value in the string to compared to
int holdVal;
int located; // true or false
for(curr = 1; curr < MAXMAIN; curr++)
{
hold = colorName[curr]; // assign the point at curr to hold
holdVal = colorVal[curr];
located = 0;
for(walk = curr - 1; walk >=0 && !located;)
{
temp = colorName [walk]; //assign the first string of colorname into temp, make ready for compare
if (myStricmp(hold,temp) < 0)
{
colorName[walk +1] = colorName[walk];
colorVal[walk +1] = colorVal[walk];
walk--; // move 1 index
}
else
{
located = 1;
}
}
colorName[walk+1] = hold;
colorVal[walk+1] = holdVal;
}
return;
}
A much cleaner method is grouping colorName and colorVal into a struct and then sorting the struct.
Code:
struct color
{
char* name;
int val;
};
void sort_color(struct color a[], int limit)
{
for (int x = 1; x < limit; ++x)
{
struct color hold = a[x];
bool located = false;
int y;
for (y = x - 1; y >= 0 && !located; )
{
if (myStricmp(hold.name, color[y].name) < 0)
{
color[y+1] = color[y];
--y;
}
else
{
located = true;
}
}
color[y+1] = hold;
}
}