I cannot wrap my mind around doing this logically. I have mapped out all possibilities for sorting and based my algorithm on that.
ABC
ACB
BAC
BCA
CAB
CBA
Only six possible combinations for 3 strings, and so, I thought it a very quick and easy solution to hardcode this with conditionals. See code;
char str1[x]; // where x is some constant value
char str2[x];
char str3[x];
char temp[x];
if (strcmp(str1, str2) > 0)
{
strcpy(temp, str1);
strcpy(str1, str2);
strcpy(str2, temp);
}
else if (strcmp(str2, str3) > 0)
{
strcpy(temp, str2);
strcpy(str2, str3);
strcpy(str3, temp);
}
else if (strcmp(str1, str3) > 0)
{
strcpy(temp, str1);
strcpy(str1, str3);
strcpy(str3, temp);
}
Essentially I would like to take any variation of ABC for example and sort it to ABC. i.e. BAC -> ABC, CAB -> ABC.