A last issue
Code:
for (int x = 0; x < strlen(argv[1]); x++){
for (int y = 0; y < strlen(argv[1]); y++)
/*........*/
strlen(argv[1]); IS EVALUATED every time a cicle is run. Therefore your code like it is now, is extremely inefficient.
Write this:
Code:
int len = strlen(argv[1])-1;
for (int x = 0; x < len; x++){
for (int y = 0; y < len; y++)
/*........*/
So strlen is evaluated only once.
Why len = ... -1 ?? Note that list[y] = list[y+1];
y+1 would refer to the string's terminating zero
Second, I sugested optimizing internal loop
Consider the following:
Code:
//input
S W R T I K F G
//and size
len = strlen(argv[1]);//len = 7
//your internal cicle
for (int y = 0; y < strlen(argv[1]); y++)
//after 0 iterations
S W R T I K F G
//after 1 iterations
S R T I K F G W
//after 2 iterations
R S I K F G T W
//after 3 iterations
R I K F G S T W
//after 4 iterations
I K F G R S T W
//after 5 iterations
I F G K R S T W
//after 6 iterations
F G I K R S T W
//after 7 iterations
F G I K R S T W
After N iterations the N final elements are already sorted, therefore runing the internal cicle all the way till the last element is unecessary, even worst, waste of CPU. So if N elements are sorted (N is stored in your var x) you cicle may been written like this:
Code:
for (int y = 0; y < len-x-1; y++)
What I'm sugesting is a correct bubble sort algorithm, you a less eficient one.